HDU 6199 gems gems gems (2017沈阳网赛
来源:互联网 发布:skycc软件 编辑:程序博客网 时间:2024/06/02 08:02
题意:
有一堆数, 两个人轮流取, 只能从最左边开始选择, 假设上一个人选了k 个牌, 那么下一个人只能选择k 或 k + 1 张牌。 第一个人得分为A, 第二个人得分为B, 求A- B, 每个人的策略都想使自己得分尽可能的高。
思路:
是UVA 10891 的变形把。
我们令dp[i][j] 表示从i 位置开始选择, 能选j 个牌的最大分数差值。
那么直接根据j 来转移即可。
总共两种选择, 要么选j 个, 要么选j + 1个, 处理个前缀和即可。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 20000 + 1;const int inf = 0x3f3f3f3f;int dp[maxn][200];bool vis[maxn][200];int a[maxn], n;int sum[maxn], ks;int dfs(int pos, int k){ int& ans = dp[pos][k]; if (vis[pos][k] == 1) return ans; vis[pos][k] = 1; if (pos > n){ return ans = 0; } if (pos + k - 1 > n){ return ans = 0; } ans = -inf; int lak = pos + k - 1; int lak1 = pos + k; if (lak <= n){ ans = max(ans, sum[lak] - sum[pos - 1] - dfs(lak + 1, k)); } if (lak1 <= n){ ans = max(ans, sum[lak+1] - sum[pos - 1] - dfs(lak1 + 1, k + 1)); } return ans;}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d", &n); memset(vis,0,sizeof vis); for (int i = 1; i <= n; ++i){ scanf("%d", &a[i]); sum[i] = sum[i-1] + a[i]; } printf("%d\n", dfs(1, 1)); } return 0;}
gems gems gems
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1296 Accepted Submission(s): 276
Problem Description
Now there are n gems, each of which has its own value. Alice and Bob play a game with these n gems.
They place the gems in a row and decide to take turns to take gems from left to right.
Alice goes first and takes 1 or 2 gems from the left. After that, on each turn a player can takek or k+1 gems if the other player takes k gems in the previous turn. The game ends when there are no gems left or the current player can't take k or k+1 gems.
Your task is to determine the difference between the total value of gems Alice took and Bob took. Assume both players play optimally. Alice wants to maximize the difference while Bob wants to minimize it.
They place the gems in a row and decide to take turns to take gems from left to right.
Alice goes first and takes 1 or 2 gems from the left. After that, on each turn a player can take
Your task is to determine the difference between the total value of gems Alice took and Bob took. Assume both players play optimally. Alice wants to maximize the difference while Bob wants to minimize it.
Input
The first line contains an integer T (1≤T≤10 ), the number of the test cases.
For each test case:
the first line contains a numbersn (1≤n≤20000 );
the second line contains n numbers:V1,V2…Vn . (−100000≤Vi≤100000 )
For each test case:
the first line contains a numbers
the second line contains n numbers:
Output
For each test case, print a single number in a line: the difference between the total value of gems Alice took and the total value of gems Bob took.
Sample Input
131 3 2
Sample Output
4
Source
2017 ACM/ICPC Asia Regional Shenyang Online
Recommend
liuyiding | We have carefully selected several similar problems for you: 6205 6204 6203 6202 6201
阅读全文
0 0
- HDU 6199 gems gems gems (2017沈阳网赛
- HDU 6199 gems gems gems 2017沈阳网络赛 1006
- HDU 6199 gems gems gems (2017沈阳网络赛)
- 2017沈阳网络赛 HDU 6199 gems gems gems
- HDU 6199 gems gems gems
- hdu 6199 gems gems gems
- HDU 6199 gems gems gems dp
- hdu 6199 gems gems gems dp
- hdu 6199 gems gems gems(DP)
- 【2017沈阳网络赛】1006 hdu6199 gems gems gems 动态规划
- HDU 6199 gems gems gems [DP+DP优化]
- HDU 6199 gems gems gems dp(逆推)
- HDU 6199 gems gems gems (DP, 2017 ACM/ICPC Asia Regional Shenyang Online)
- hdu 4778 Gems Fight!
- hdu 4778Gems Fight!
- HDU 4778 Gems Fight!
- HDU 4778 Gems Fight!
- hdu 4778 Gems Fight!
- 前端模块化
- 81. Search in Rotated Sorted Array II
- 面向对象
- Java 中的数值类型转换
- vm linux 快照clone
- HDU 6199 gems gems gems (2017沈阳网赛
- AngularJS1.4.6
- 划船不靠桨
- CentOS 7 下 Zabbix 3.2 安装
- CSDN如何转载别人的文章
- H
- 字符串全排列
- #CCF准备一年日常刷题#201503-1图像旋转
- Android中的数据存储方式