#include <cstdio>
#include <algorithm>
#include <cstring>
int n,e,a[300],f[210][210],ans;
inline void read(int &x) {
x = 0;
char c = getchar();
while(c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x*10 + c - '0', c = getchar();
return;
}
struct two{
int x, y;
}t[210];
int dp(int l) {
for(int r=1; r<=n; r++) {
for(int i=l; i<=l+n-1-r; i++) {
int j = i + r;
for(int k=i; k<j; k++) {
f[i][j] = std::max(f[i][j], f[i][k] + f[k+1][j] + t[i].x*t[k].y*t[j].y);
}
}
}
return f[l][l+n-1];
}
int main() {
read(n);
for(int i=1; i<=n; i++)
read(a[i]);
for(int i=1; i<=n-1; i++) {
t[i].x = t[i+n].x = a[i];
t[i].y = t[i+n].y = a[i+1];
}
t[n].x = a[n];
t[n].y = a[1];
for(int i=1; i<=n; i++)
ans = std::max(ans, dp(i));
printf("%d",ans);
}
能量项链 NOIP2006 Codevs1154
最新推荐文章于 2019-08-06 22:07:04 发布