N (2 <=n<=200, and even) a sequence of positive integers placed on a game platform, a, b two people take a number from both ends of the sequence, take the number after the number is removed and added to the player's score, when the number of time, the game is over. To win the final score (a first take, the same score count a wins). Try to ask:
How to take the number, in order to make A and B score the biggest gap?
(Hint: A, b Both sides are trying to win)
{
Not greed, not simulation.
To win is not to take the biggest from both ends
F[I,J] Indicates the maximum score that can be obtained by a person who first takes a number in the interval i,j
Initial value F[i,i]:=ai;
From the first and District J of the most
Maximum difference-one person scored the highest!
}
varA:Array[0.. -] ofLongint; F:Array[0.. -,0.. -] ofLongint; Sum:Array[0.. -] ofLongint; I,n,j,p:longint; functionmin (x,y:longint): Longint; begin ifX<y ThenExit (x)Elseexit (y); End; beginread (n); fori:=1 toN Doread (a[i]); fori:=1 toN Dof[i,i]:=A[i]; fori:=1 toN Do forj:=1 toI DoSum[i]:=sum[i]+A[j]; fori:=1 toN-1 Do forj:=1 toN-i Do beginP:=i+J; F[J,P]:=sum[p]-sum[j-1]-min (f[j+1, p],f[j,p-1]); End; Writeln (f[1, N],' ', sum[n]-f[1, N])
End.
Take several games