显示代码纯文本
#include<cstdio>
#include<cstring>
#define INF 0x7fffffff
using namespace std;
int n,a[210],f1[210][210],f2[210][210],sum[210]={0},minn=INF,maxx=0,i,j,k;
inline int min(int a,int b)
{return a<b?a:b;}
inline int max(int a,int b)
{return a>b?a:b;}
int Main()
{
freopen("stone2.in","r",stdin);freopen("stone2.out","w",stdout);
memset(f1,127,sizeof(f1));
memset(f2,0,sizeof(f2));
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-1]+a[i];
}
for(i=n+1;i<=(n<<1);i++)
{
a[i]=a[i-n];
sum[i]=sum[i-1]+a[i];
}
for(i=1;i<=(n<<1);i++)f1[i][i]=f2[i][i]=0;
for(i=(n<<1)-1;i>=1;i--)for(j=i+1;j<=(n<<1);j++)for(k=i;k<=j-1;k++)
{
f1[i][j]=min(f1[i][j],f1[i][k]+f1[k+1][j]+sum[j]-sum[i-1]);
f2[i][j]=max(f2[i][j],f2[i][k]+f2[k+1][j]+sum[j]-sum[i-1]);
}
for(i=1;i<=n;i++)
{
minn=min(minn,f1[i][i+n-1]);
maxx=max(maxx,f2[i][i+n-1]);
}
printf("%d\n%d\n",minn,maxx);
return 0;
}
int main(){;}
int syy=Main();