题目链接:http://vjudge.net/contest/140891#problem/F
A和B都足够聪明,只有我傻,想了好久才把代码和题意对应上[大哭]
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
const int INF=0x3f3f3f3f; int dp[][];
int a[],sum[]; int main(){
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
for(int t=; t<=T; t++){
int n;
scanf("%d",&n);
memset(sum,,sizeof(sum));
for(int i=; i<=n; i++){
scanf("%d",&a[i]);
dp[i][i]=a[i];
sum[i]=sum[i-]+a[i];
}
for(int d=; d<n; d++)
for(int i=; i+d<=n; i++){
int j=i+d;
dp[i][j]=sum[j]-sum[i-];
for(int k=i; k<j; k++)
dp[i][j]=max(dp[i][j],max(sum[k]-sum[i-]-dp[k+][j],sum[j]-sum[k]-dp[i][k]));
}
printf("Case %d: %d\n",t,dp[][n]);
}
return ;
}