https://daniu.luogu.org/problemnew/show/P2964

dp[i][j] 表示桌面上还剩i枚硬币时,上一次取走了j个的最大得分

枚举这一次要拿k个,转移到dp[i-k][k]

dp[i][j]=max(sum[i]-dp[i-k][k])

因为 上一次取走j个和取走j-1个 k的取值范围 只相差 2*j-1 和 2*j

所以 直接 dp[i][j]=dp[i][j-1]

然后k分别等于  2*j-1 和 2*j,转移

最后输出dp[n][1],因为先手可以拿1个或2个,相当于上次取走1个

#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 2001 int dp[N][N]; int a[N],sum[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int main()
{
int n;
read(n);
for(int i=;i<=n;++i) read(a[n-i+]);
for(int i=;i<=n;++i) sum[i]=sum[i-]+a[i];
int k;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
{
dp[i][j]=dp[i][j-];
k=(j<<)-;
if(k<=i) dp[i][j]=max(dp[i][j],sum[i]-dp[i-k][k]);
++k;
if(k<=i) dp[i][j]=max(dp[i][j],sum[i]-dp[i-k][k]);
}
cout<<dp[n][];
}

题目描述

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.

输入输出样例

输入样例#1: 复制

5
1
3
1
7
2
输出样例#1: 复制

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).

[USACO09NOV]硬币的游戏A Coin Game的更多相关文章

  1. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  2. [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  3. [LUOGU2964] [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  4. LUOGU P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  5. P2964 [USACO09NOV]硬币的游戏A Coin Game (DP)

    题意:n颗硬币 两个人从前往后按顺序拿 如果上一个人拿了i颗 那么下一个可以拿1-2*i颗 问先手能获得的最大收益 题解:比较典型的最大最小最大最小..DP了 但是暴力做的话是n^3 所以就体现出了这 ...

  6. [USACO09NOV]硬币的游戏 博弈 dp

    LINK : coin game 这道题 超级经典去年这个时候我就看过题目了 但时至今日还不会/cy 觉得在做比赛的题目的时候少写省选的题目 多做水题多做不难也不简单的题目就好了. 由于我是真的不会博 ...

  7. 【P2964】硬币的游戏(DP+前缀和)

    一道DP,思维难度真是不小. 首先对于这个题的数据,我们可以发现差不多可以支持n^2logn,但是貌似也不会有这种复杂度的线性DP(至少这个题看上去不是这样).所以我们考虑N^2做法.因为求得是价值和 ...

  8. 洛谷 [P2964] 硬币的游戏

    博弈论+dp 依旧是博弈论的壳子,但问的是最大值,所以要dp 设 dp[i][j] 表示该取 i 号硬币,上一次取了 j 个的先手能取的最大值, 因为每次从小到大枚举复杂度太高,所以我们要从 dp[i ...

  9. 题解 SP5271 XOINC - A Coin Game

    SP5271 XOINC - A Coin Game 双倍经验:P2964 [USACO09NOV]硬币的游戏A Coin Game O3做法(TLE):枚举i,j,k,即剩下i枚金币,上一轮选了j枚 ...

随机推荐

  1. The user survey(用户调查)

    在周末,我们找了一些人来进行了一个调查,鉴于选择困难,我们只找到了几个真正的小学生,没有找到家长,其余那些都是找大学生来做调查的,我们和他们说,让他们把自己的立场看成是小学生或家长.下面是我们整理出来 ...

  2. 分类Category的概念和使用流程

    一.了解 1.分类的概念: category:类别.类目.分类 2.分类的作用: 将1个类中不同方法分到多个不同的文件中存储 可以在不修改原来类的基础上,为这个类扩充一些方法 注意: 分类中只能增加方 ...

  3. 【流程图】购物车、三级菜单、sed替换

  4. 【bzoj5084】hashit 广义后缀自动机+树链的并+STL-set

    题目描述 你有一个字符串S,一开始为空串,要求支持两种操作 在S后面加入字母C 删除S最后一个字母 问每次操作后S有多少个两两不同的连续子串 输入 一行一个字符串Q,表示对S的操作 如果第i个字母是小 ...

  5. BZOJ5127 数据校验

    第一眼看错题以为只是要求区间值域连续,那莫队一发维护形成的值域段数量就行了. 原题这个条件相当于区间内相邻数差的绝对值不超过1.所以只要对这个做个前缀和就……完了? #include<iostr ...

  6. ORA-01034和ORA-27101的解决方法

    问题所在: 1.要登录的数据库实例内容配置内容错误,联系负责该机子的管理员看原因

  7. 【刷题】BZOJ 3531 [Sdoi2014]旅行

    Description S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足 从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教.绝地教都是常见的信仰 ...

  8. 【比赛】NOIP2017 时间复杂度

    恶心的模拟题,考场上犯了一堆错误,多组数据清空没清完.数组开小...民间都是50分,结果CCF90.. 考完后随便改改就过了,还好只少了10分,如果真的是50,我估计会疯掉. 因为考场的时候没写好,所 ...

  9. 【XSY1841】Intervals

    Description 在一个长度为m的序列中选出n个区间,这些区间互不包含,且至少有一个区间的左端点为x. 问有多少种方案,注意交换两个区间的顺序视为不同方案. ​ 答案很大,输出模10000000 ...

  10. 【BZOJ4205】卡牌配对

    Description 现在有一种卡牌游戏,每张卡牌上有三个属性值:A,B,C.把卡牌分为X,Y两类,分别有n1,n2张. 两张卡牌能够配对,当且仅当,存在至多一项属性值使得两张卡牌该项属性值互质,且 ...