【题目链接】
【题解大意】
这题好水,可我还是调了一会,以下为调试中出现过的错误:
1.更新取值时弄清楚区间范围是[l,k][k+1,r]还是[l,k][k,r]
2.对于环形处理时左端点的取值最大可以到达(n<<1)要记住
3.每题的枚举k具体的起止到底是[l,r]还是[l+1,r]还是[l+1,r-1]...要根据题目的理解各异
【code】
#includeusing namespace std;#define File ""#define ll long long#define ull unsigned long long#define rep(k,i,j) for(int k = i;k <= j; ++k)#define FOR(k,i,j) for(int k = i;k >= j; --k)inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout);}inline int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0'; ch=getchar();} return x*f;}const int mxn = 105;int n;int a[mxn<<1],f[mxn<<1][mxn<<1];int main(){// file(); n = read(); rep(i,1,n) a[n+i] = a[i] = read(); memset(f,0,sizeof f); rep(i,1,n<<1) f[i][i] = a[i]; rep(len,2,n+1){ rep(l,1,(n<<1)-len+1){ int r = l+len-1; rep(k,l+1,r-1) f[l][r] = max(f[l][r],f[l][k]+f[k][r]+a[l]*a[k]*a[r]); } }// rep(i,1,n) printf("%d\n",f[i][i+n]);// puts(""); int ans = 0; rep(i,1,n) ans = max(ans,f[i][i+n]); printf("%d\n",ans); return 0;}/*42 3 5 10*/