这道题DP。
设fa[i,j]表示 i~j 这个区间里先手可以获得的最优值
设ans[i,j]表示 i~j 这个区间的和
#include<cstdio>
#include<algorithm>
#define sum(x,y) qz[y]-qz[x-1]
using namespace std;
int n,a[101],f[101][101],qz[101];
inline int read()
{
int x=0; char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
int main()
{
freopen("game.in","r",stdin);
// freopen("game.out","w",stdout);
n=read();
for (int i=1;i<=n;i++)
f[i][i]=a[i]=read(),qz[i]=qz[i-1]+a[i];
for (int i=n-1;i>0;i--)
for (int j=i+1;j<=n;j++)
f[i][j]=sum(i,j)-min(f[i][j-1],f[i+1][j]);
printf("%d %d
",f[1][n],qz[n]-f[1][n]);
return 0;
}