合并类动归就是要注意区间!!!
合并类动归就是要注意区间!!!
合并类动归就是要注意区间!!!
合并类动归就是要注意区间!!!
合并类动归就是要注意区间!!!
/*
状态定义:dp[i][j]表示合并i到j时的最大得分 sum_stone[i][j]表示i到j石子个数
转移方程:dp[i][j]=max{dp[i][k]+dp[k+1][j]+sum_stone[i][j],dp[i][j]}
边界:max{dp[i][n+i-1]}为答案
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=500;
int sum[maxn],dp[maxn][maxn][2],st[maxn];//0 for min,1 for max
int n;
void Init(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&st[i]);
st[i+n]=st[i];
}
for(int i=1;i<=n*2;i++)sum[i]=sum[i-1]+st[i];
}
void DP(){
for(int p=1;p<n;p++)//枚举合并区间长度
for(int i=1,j=i+p;(i<n*2) && (j<=n*2);i++,j=i+p){//确定区间起终点
dp[i][j][0]=1<<30,dp[i][j][1]=0;
for(int k=i;k<j;k++){//枚举断点
dp[i][j][0]=min(dp[i][k][0]+dp[k+1][j][0]+sum[j]-sum[i-1],dp[i][j][0]);
dp[i][j][1]=max(dp[i][k][1]+dp[k+1][j][1]+sum[j]-sum[i-1],dp[i][j][1]);
}
}
int _max=-1,_min=1<<30;
for(int i=1;i<=n;i++){
_max=max(_max,dp[i][n+i-1][1]);
_min=min(_min,dp[i][n+i-1][0]);
}
printf("%d\n%d",_min,_max);
}
int main()
{
#ifndef DEBUG
string FileName="stone2";
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#endif
Init();
DP();
}