环形区间dp+矩阵连乘
#include
#include
//类似于矩阵连乘的一道题,将维度存下来一共有n+1个数字
using namespace std;
const int N = 205;
int f[N][N];
int a[N];
int n;
int main() {
cin>>n;
for(int i = 1;i<=n;i++) {
cin >> a[i];
a[n+i] = a[i];
}
for(int len = 3;len<=n+1;len++){
for(int l = 1;l+len-1<=n*2;l++){
int r = l+len-1;
for(int i = l+1;i<r;i++){
f[l][r] = max(f[l][r],f[l][i]+f[i][r]+a[l]*a[r]*a[i]);
}
}
}
int res = 0;
for(int i = 1;i<=n;i++){
res = max(res,f[i][n+i]);
}
cout<<res;
return 0;
}