环形的解决很巧妙

 #include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+; int a[MAXN*],dp[MAXN*][MAXN*];int sum[MAXN*];int df[MAXN*][MAXN*]; int main()
{
int n;scanf("%d",&n);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=n+;i<=n+n;i++)
{
a[i]=a[i-n]; sum[i]=sum[i-]+a[i];
}
for(int l=;l<=n;l++)
{ for(int i=;i<=n+n;i++)
{
int j=l+i-;
df[i][j]=INF;
if(j>n+n) continue;
for(int k=i;k<j;k++)
{
dp[i][j]=max(dp[i][k]+dp[k+][j]+sum[j]-sum[i-],dp[i][j]);
df[i][j]=min(df[i][k]+df[k+][j]+sum[j]-sum[i-],df[i][j]);
} }
}
int ans1=;
int ans2=INF;
for(int i=;i<=n;i++)
{
int j=i+n-;
if(j>n+n) break;
ans1=max(dp[i][j],ans1);
ans2=min(df[i][j],ans2); }
cout << ans2<<endl<<ans1<<endl;
return ;
}
05-08 15:50