codevs3196 Gold Treasures

Source: Internet
Author: User

Title Description Description

The little boy finally arrived at the treasure point, he had found an alien (called Pluto) outside. The treasure is some space gold, with n piles lined up with Xi gold in each heap. Xiao and Pluto decided to take the gold in turn, and the rule was to take a heap of gold from the far left or right, until all the gold was removed. First take, two people are the optimal strategy to choose, to seek the final income of two people.

Enter a description input Description

The first line is positive n (≤500), and the second behaves n positive integer XI (≤300), which represents the number of gold per heap.

outputs description output Description

Only two integers, each of which represents the score of a Pluto and a single space.

sample input to sample

6

4 7 2 9 5 2

Sample output Sample outputs

18 11

Positive solution: DP

Problem Solving Report:
It's a bit of a lie when you see this is a game. Well, in fact, it's only thought.

Obviously DP feasible, F[I][J] represents the interval from I to J of the optimal strategy, the last f[1][n] that is the initiator score, the sum of the total minus the best value is the bottom of the score.

Transfer also better think, just have a place to compare God. Obviously from the left side of the selection of a bunch or from the right end of the selection of a bunch of transfer, and we get the smaller that value, because we need to make the decision to contribute as small as possible.

See the code for details.

1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN =501; + intN; A intA[MAXN],SUM[MAXN]; at intF[MAXN][MAXN];//F[i][j] represents the optimal strategy score from I to J -  -InlineintGetint () - { -        intw=0, q=0; -        CharC=GetChar (); in         while((c<'0'|| C>'9') && c!='-') c=GetChar (); -        if(c=='-') q=1, c=GetChar (); to         while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); +        returnQ? -w:w; - } the  *InlinevoidWork () { $n=getint ();Panax Notoginseng      for(intI=1; i<=n;i++) A[i]=getint (), f[i][i]=a[i],sum[i]=sum[i-1]+A[i]; -      for(intlen=1; len<=n-1; len++) the      for(intI=1; i<=n-len;i++) +f[i][i+len]=sum[i+len]-sum[i-1]-min (f[i+1][i+len],f[i][i+len-1]);//minus part is the decision minimum value of the FLAC Aprintf"%d%d", f[1][n],sum[n]-f[1][n]);//the sum minus the initiator optimal decision is the goal of the the } +  - intMain () $ { $ Work (); -   return 0; -}

codevs3196 Gold Treasures

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.