Title Description
Farmer John's cows like-to-play coin games so FJ have invented with a new two-player coin game called Xoinc for them.
Initially a stack of n (5 <= n <= 2,000) coins sits on the ground; Coin I from the top have integer value c_i (1 <= c_i <= 100,000).
The first player starts the game by taking the top one or both coins (C_1 and maybe c_2) from the stack. If The first player takes just the top coin, the second player may take the following one or both coins in the next turn. If The first player takes the coins then the second player could take the top one, both, three or four coins from the stack. In each turn, the current player must take at least one coin and at the very same times the amount of coins last taken by the O Pposing player. The game was over when there was no more coins to take.
Afterwards, they can use the value of the coins they has taken from the stack to buy treats from FJ, so naturally, their Purpose in the game are to maximize the total value of the coins they take. Assuming the second player plays optimally to maximize he own winnings, what's the highest total value that the first PL Ayer can has when the game was over?
MEMORY limit:20 MB
Farmer John's cow likes to play coin games.
Initially, a stack of n coins is placed on the ground, and the value of the first coin from the heap topness is CI
When you start playing a game, the first player can take one or two coins from the top of the heap. If the first player takes only one coin from the top of the heap, The second player can then take one or two coins. If the first player takes two coins, the second player can take the three or 4 coins. In each round, the current player takes at least one coin, at most, twice times the number of coins taken by the opponent last time. When there are no coins to take, the game is over. .
Two players want to get the most money in the coin. How much will the first player get at the end of the game?
Input/output format
Input format:
Output format:
- Line 1: A single integer representing the maximum value, the can is made by the first player.
Input and Output Sample input example # #:
Sample # # of output:
Description
There is five coins with the values 1, 3, 1, 7, and 2.
The first player starts by taking a single coin (value 1). The opponent takes one coin as well (value 3). The first player takes the other coins (values 1 and 7--Total 9). The second player gets the leftover coin (value 2--total 5).,
And that game of sum I really want to
But to constrain the selection of several
F[I][J] means that 1 to I, the last candidate, J, the maximum number of players to score
Violent transfer enumeration f[i-k][k], found F[i][j] only two more transfers than f[i][j-1], can optimize
about the game: F[i][j] is the number 1th, the natural choice S[i]-f[i-k][k] Max, the f[i-k][k in this is number 2nd .
The answer is f[n][1], all left, number 1th, the largest, you can choose one or two
PS: Note that C should be inverted.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=2e3+5; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,c[n],s[n],f[n][n];voiddp () { for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++) {F[i][j]=f[i][j-1]; intk=2*J; if(i-k>=0) F[i][j]=max (f[i][j],s[i]-f[i-K] [K]); K=2*j-1; if(i-k>=0) F[i][j]=max (f[i][j],s[i]-f[i-K] [K]); } }}intMain () {n=read (); for(inti=n;i>=1; i--) c[i]=read (); for(intI=1; i<=n;i++) s[i]=s[i-1]+C[i]; DP (); printf ("%d", f[n][1]);}
Rokua P2964 [Usaco09nov] Coins games a Coin game