AcWing 320. 能量项链
题意:
题解:
和环形石头合并基本一样
代码:
#include<bits/stdc++.h>
#define debug(a,b) printf("%s = %d\n",a,b);
typedef long long ll;
using namespace std;inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w;
}
const int maxn=200;
int dp[maxn][maxn];
int a[maxn];
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);a[i+n]=a[i];}for(int len=2;len<=n+1;len++){for(int i=1;i+len-1<=2*n;i++){int j=i+len-1;for(int k=i+1;k<j;k++){dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j]+a[i]*a[j]*a[k]);}}}int maxx=0;for(int i=1;i<=n;i++){maxx=max(maxx,dp[i][i+n]);}cout<<maxx;
}