https://www.luogu.org/problemnew/show/P1063
这个并不是每次只能从两边扩展的,可以从中间断开。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[205];
ll dp[205][205];
ll calc(int i,int m,int j) {
return a[i]*a[m]*a[j];
}
int main() {
#ifdef Yinku
freopen("Yinku.in","r",stdin);
#endif // Yinku
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
a[i+n]=a[i];
}
ll maxans=0;
for(int l=3; l<=n+1; l++) {
for(int i=1,j; (j=i+l-1)<=2*n; i++) {
for(int k=i+1;k<=j-1;k++){
dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j]+calc(i,k,j));
}
}
}
for(int b=1;b<=n;b++)
maxans=max(maxans,dp[b][b+n]);
printf("%lld\n",maxans);
return 0;
}