标签:输出 read get pre for 输入 通过 define name
\[ dp[l][r]=Max{\{} dp[l][k]+dp[k][r]+val[l]*val[k]*val[r] {\}} \]
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 101
using namespace std;
long long dp[maxn<<1][maxn<<1],ans;
int n,val[maxn<<1];
inline int read(){
register int x(0),f(1); register char c(getchar());
while(c<'0'||'9'<c){ if(c=='-') f=-1; c=getchar(); }
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int main(){
n=read();
for(register int i=1;i<=n;i++) val[i]=val[i+n]=read();
for(register int len=2;len<=n+1;len++){
for(register int l=1,r=len;r<=(n<<1);l++,r++){
for(register int k=l+1;k<r;k++){
dp[l][r]=max(dp[l][r],dp[l][k]+dp[k][r]+val[l]*val[k]*val[r]);
}
}
}
for(register int i=1;i<=n;i++) ans=max(ans,dp[i][i+n]);
printf("%lld\n",ans);
return 0;
}
标签:输出 read get pre for 输入 通过 define name
原文地址:https://www.cnblogs.com/akura/p/11053820.html