# hdu 6199 沈阳网络赛---gems gems gems（DP）

Problem Description
Now there are

Input
The first line contains an integer

Output
For each test case, print a single number in a line: the difference between the total value of gems Alice took and the total value of gems Bob took.

Sample Input
1
3
1 3 2

Sample Output
4

另外，本题空间限制比较紧，所以需要使用滚动数组，第一维设为205即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=20005;
const int M=203;
int sum[N];
int dp[M][2][205];

int main()
{
int T; cin>>T;
while(T--)
{
sum[0]=0;
memset(dp,0,sizeof(dp));
int n; scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&sum[i]),sum[i]+=sum[i-1];
for(int i=n;i>=1;i--)
{
for(int j=1;j<M;j++)
{
if(i+j-1>n) break;

int tmp=sum[i+j-1]-sum[i-1], t;
if(i+j+j<=n) t=min(dp[(i+j)%M][1][j],dp[(i+j)%M][1][j+1]);
else if(i+j+j-1<=n) t=dp[(i+j)%M][1][j];
else t=0;
dp[i%M][0][j]=tmp+t;

if(i+j+j<=n) t=max(dp[(i+j)%M][0][j],dp[(i+j)%M][0][j+1]);
else if(i+j+j-1<=n) t=dp[(i+j)%M][0][j];
else t=0;
dp[i%M][1][j]=t-tmp;
}
}
int ans;
if(n>=2) ans=max(dp[1][0][1],dp[1][0][2]);
else ans=dp[1][0][1];
printf("%d\n",ans);
}
return 0;
}

posted @ 2017-09-11 21:14 茶飘香~ 阅读(...) 评论(...) 编辑 收藏