Take several games

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.