洛谷 P2964 [USACO09NOV] 硬币的游戏A Coin Game
来源:互联网 发布:明道办公软件官网 编辑:程序博客网 时间:2024/05/21 19:44
题目描述
Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them.
Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <= 100,000).
The first player starts the game by taking the top one or two coins (C_1 and maybe C_2) from the stack. If the first player takes just the top coin, the second player may take the following one or two coins in the next turn. If the first player takes two coins then the second player may take the top one, two, three or four coins from the stack. In each turn, the current player must take at least one coin and at most two times the amount of coins last taken by the opposing player. The game is over when there are no more coins to take.
Afterwards, they can use the value of the coins they have taken from the stack to buy treats from FJ, so naturally, their purpose in the game is to maximize the total value of the coins they take. Assuming the second player plays optimally to maximize his own winnings, what is the highest total value that the first player can have when the game is over?
MEMORY LIMIT: 20 MB
农夫约翰的奶牛喜欢玩硬币游戏.
初始时,一个有N枚硬币的堆栈放在地上,从堆顶数起的第i枚硬币的币值 为Ci
开始玩游戏时,第一个玩家可以从堆顶拿走一枚或两枚硬币.如果第一个玩家只拿走堆顶的 一枚硬币,那么第二个玩家可以拿走随后的一枚或两枚硬币.如果第一个玩家拿走两枚硬币,则第二个玩家可以拿走1,2,3,或4枚硬币.在每一轮中,当前的玩家至少拿走一枚硬币,至多拿 走对手上一次所拿硬币数量的两倍.当没有硬币可拿时,游戏结束.
两个玩家都希望拿到最多钱数的硬币.请问,当游戏结束时,第一个玩家最多能拿多少钱 呢?
输入输出格式
输入格式:Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single integer: C_i
- Line 1: A single integer representing the maximum value that can be made by the first player.
输入输出样例
5 1 3 1 7 2
9
说明
There are five coins with the values 1, 3, 1, 7, and 2.
The first player starts by taking a single coin (value 1). The opponent takes one coin as well (value 3). The first player takes two more coins (values 1 and 7 -- total 9). The second player gets the leftover coin (value 2-- total 5).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DP+博弈论~
和上一道差不多的做法,只是要多限制一下取数,而且只能从一边取~
用f[i][j]表示该取i,上一次取了j个的最大得分,则因为所有块的权值都>0,所以只要用2*j和2*j-1来更新答案就可以了,具体DP方程见代码~
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int n,a[2002],f[2001][2001],ans;int read(){int totnum=0,f=1;char ch=getchar();while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') {totnum=(totnum<<1)+(totnum<<3)+ch-'0';ch=getchar();}return totnum*f;}int main(){n=read();for(int i=n;i;i--) a[i]=read();for(int i=2;i<=n;i++) a[i]+=a[i-1],f[i][i]=a[i];for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { f[i][j]=f[i][j-1]; if(i>=2*j) f[i][j]=max(f[i][j],a[i]-f[i-2*j][2*j]); if(i+1>=2*j) f[i][j]=max(f[i][j],a[i]-f[i-2*j+1][2*j-1]); }printf("%d\n",f[n][1]);return 0;}
- 洛谷 P2964 [USACO09NOV] 硬币的游戏A Coin Game
- 博弈论+dp——洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game
- 洛谷2964 A Coin Game
- A Coin Game
- HOJ 2939 Coin Question-------放硬币游戏
- 洛谷【P2734】 游戏 A Game
- HDOJ 3537 Daizhenyang's Coin (翻硬币游戏)
- hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)
- hdu3537 Daizhenyang's Coin 翻硬币,(Mock Turtles游戏)
- HDU 3537 Daizhenyang's Coin (博弈论、翻硬币游戏)
- Coin Game
- 硬币 coin题解
- Coin Change【硬币找零】
- DP7 两道换硬币的问题 Coin Change @geeksforgeeks
- Coin Change - UVa 674 换硬币的dp
- USACO 2009 Nov Silver 1.A Coin Game 动态规划
- hdu 4642 Fliping game 翻硬币游戏 抓住特征变量
- uva674 - Coin Change(硬币找零)
- jzoj 5000. 【NOI2017模拟3.4】保镖 hall定理+搜索
- redis集群和Sentinel功能
- iocp原理
- C++ stringstream clear()和.str("")
- Retrofit + RxJava 的结合使用
- 洛谷 P2964 [USACO09NOV] 硬币的游戏A Coin Game
- 【BZOJ 1019】 [SHOI2008]汉诺塔
- TCP标志位中的PSH和URG的区别和联系
- NYOJ 1085 数单词 【AC自动机】
- p元素包含div元素的问题
- 博为峰Java技术文章 ——JavaSE Swing列表框双击事件的处理Ⅱ
- 字符串反转
- Should I Use a Property or an Instance Variable?
- openCV3.X 对图像的常用基础操作(自用,都是图像存储用的Mat,不适用*array,或者Iplmage之类)