bzoj2101[usaco2010 dec]treasure Chest Treasure Chest
Test instructions
Give a sequence, A and b take a number of turns, who take the sum of the number of large who wins. Each time can only take the sequence at both ends, ask a can fetch the sum of the maximum is how much. Suppose both people use the optimal strategy. Sequence size ≤5000
Exercises
Dp. F[i][j][0]=max (F[i+1][j][1]+a[i],f[i][j-1][1]+a[j]), F[i][j][1]=min (F[i+1][j][0],f[i][j-1][0]).
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 50106 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - inta[maxn],f[2][maxn][2],n;BOOLx, y; the intMain () { -N=read (); Inc (I,1, n) a[i]=read (); x=0; y=1; - for(inti=n;i>=1; i--){ -Inc (J,1, N) f[y][j][0]=f[y][j][1]=0; + Inc (J,i,n) { -f[y][j][0]=max (f[x][j][1]+a[i],f[y][j-1][1]+a[j]); +f[y][j][1]=min (f[x][j][0],f[y][j-1][0]); A } at swap (x, y); - } -printf"%d", f[x][n][0]);return 0; -}
20160812
bzoj2101[usaco2010 dec]treasure Chest Treasure Chest *