显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[220]={0},f[220][220],fe[220][220]={0};
int m()
{
freopen("stone2.in","r",stdin);
freopen("stone2.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
a[i+n]=a[i];
}
for(int i=1;i<=2*n;i++)
{
a[i]+=a[i-1];
}
f[0][0]=0;
for(int i=1;i<=2*n;i++) f[i][i]=0;
for(int d=2;d<=n;d++)
for(int i=1;i<=2*n-d+1;i++)
{
int j=i+d-1;f[i][j]=0x7fffff;
for(int k=i;k<j;k++)
{
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+a[j]-a[i-1]);
fe[i][j]=max(fe[i][j],fe[i][k]+fe[k+1][j]+a[j]-a[i-1]);
}
}
int ans1=0x7fffffff;
int ans2=-0x7fffffff;
for(int i=1;i<=n;i++)
{
ans1=min(ans1,f[i][i+n-1]);
ans2=max(ans2,fe[i][i+n-1]);
}
printf("%d\n%d",ans1,ans2);
}
int main()
{
;
}
int k=m();