博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
10891 - Game of Sum
阅读量:5759 次
发布时间:2019-06-18

本文共 1950 字,大约阅读时间需要 6 分钟。

Problem E

Game of Sum
Input File: e.in

Output: Standard Output

 

This is a two player game. Initially there are n integer numbers in an array and players A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both ends at a time. He can take as many consecutive numbers as he wants during his time. The game ends when all numbers are taken from the array by the players. The point of each player is calculated by the summation of the numbers, which he has taken. Each player tries to achieve more points from other. If both players play optimally and player A starts the game then how much more point can player A get than player B?

Input

The input consists of a number of cases. Each case starts with a line specifying the integer n (0 < n ≤100), the number of elements in the array. After that, n numbers are given for the game. Input is terminated by a line where n=0.

 

Output

For each test case, print a number, which represents the maximum difference that the first player obtained after playing this game optimally.

 

Sample Input                                Output for Sample Input

4

4 -10 -20 7

4

1 2 3 4

0

7

10


Problem setter: Syed Monowar Hossain

Special Thanks: Derek Kisman, Mohammad Sajjad Hossain

 整数的总和是一定的,不管怎么取,任意时刻的状态都是原始序列的字串,因此我们想到用d[i][j]表示原始序列i->j个元素组成的子序列,在双方都取得最优策越的情况下先手得到的最高分,状态转移时,我们需要枚举从左边取和从右边取,这等价于给对方剩下怎样的序列。则有 d[i][j]=sum(i,j)-min(d[i+1][j],……d[j][j],d[i][j-1],……d[i][i],0),  则ans=d[1][n]-(sum(1,n)-d[1][n])

1 #include"iostream" 2 #include"cstring" 3 #include"cstdio" 4 #include"algorithm" 5 using namespace std; 6 const int ms=1005; 7 int sum[ms]; 8 int d[ms][ms]; 9 int vis[ms][ms];10 int a[ms];11 int n;12 int dp(int i,int j)13 {14     if(vis[i][j])15         return d[i][j];16     int m=0;   //全部取17     vis[i][j]=1;18     for(int k=i+1;k<=j;k++)19         m=min(m,dp(k,j));20     for(int k=i;k

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/4009780.html

你可能感兴趣的文章
生产者消费者问题理解与Java实现
查看>>
【CentOS 7架构21】,Nginx的安装#180104
查看>>
探寻Interpolator源码,自定义插值器
查看>>
一致性哈希
查看>>
mysql(待整理)
查看>>
看雪论坛502,出现安全宝?
查看>>
springSSM 使用poi导出excel(一)
查看>>
使用TMG配置×××注意事项
查看>>
使用PullToRefresh实现下拉刷新和上拉加载
查看>>
Linux文件系统
查看>>
自适应轮播图
查看>>
mysql
查看>>
SQL Server笔记2
查看>>
安装ansible以及简单使用
查看>>
切换卡TabHost控件的使用
查看>>
管家婆数据库823错误,并闩锁页错误数据恢复成功
查看>>
文华学院新闻稿
查看>>
2012年电信业八大发展趋势
查看>>
Web日志安全分析工具 v2.0发布
查看>>
JS重载
查看>>