bzoj2101[usaco2010 dec]treasure Chest Treasure Chest *

Source: Internet
Author: User

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 *

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.