hdu 6169 gems gems gems【DP】
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 take k 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.
题目意思转化为第i个人希望最大化与第i+1个人的差值。
dp[i][j]表示当前人从第i个宝石开始取j个的最大差值。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
const int M = ;
int a[N];
int sum[N];
int dp[N][M];
int main() {
int t, n, i, j, ans;
scanf("%d", &t);
sum[] = ;
while(t--) {
scanf("%d", &n);
for(i = ; i <= n; ++i) {
scanf("%d", &a[i]);
sum[i] = sum[i-] + a[i];
}
for(i = n; i >= ; --i) {
for(j = min(, n-i+); j >= ; --j) {
dp[i][j] = sum[i+j-] - sum[i-];
if(i+j+j <= n)dp[i][j] -= max(dp[i+j][j], dp[i+j][j+]);
else if(i+j+j- <= n) dp[i][j] -= dp[i+j][j];
}
}
ans = dp[][];
if(n>) ans = max(dp[][], dp[][]);
printf("%d\n", ans);
}
return ;
}
249ms
hdu 6169 gems gems gems【DP】的更多相关文章
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1078 FatMouse and Cheese【dp】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:每次仅仅能走 横着或竖着的 1~k 个格子.求最多能吃到的奶酪. 代码: #include ...
- HDU - 1134 Game of Connections 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1134 题意 给出一个n 然后有2n个点 给两个点连一条边,最后连N条边,要求所有的边不能够交叉 问最多 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- hdu 1503 LCS输出路径【dp】
hdu 1503 不知道最后怎么输出,因为公共部分只输出一次.有人说回溯输出,感觉好巧妙!其实就是下图,输出的就是那条灰色的路径,但是初始时边界一定要初始化一下,因为最第一列只能向上走,第一行只能向左 ...
- HDU 2577 How to Type【DP】
题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...
- HDU 5656 ——CA Loves GCD——————【dp】
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- hdu 1003 hdu 1231 最大连续子序列【dp】
HDU1003 HDU1231 题意自明.可能是真的进步了点,记得刚开始研究这个问题时还想了好长时间,hdu 1231还手推了很长时间,今天重新写干净利落就AC了. #include<iostr ...
- HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】
HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- Kattis - honey【DP】
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
随机推荐
- hihocoder #1529 : 不上升序列
Description 给定一个长度为 n 的非负整数序列 a[1..n]. 你每次可以花费 1 的代价给某个 a[i] 加1或者减1. 求最少需要多少代价能将这个序列变成一个不上升序列. Solut ...
- CentOS下输入输出重定向
nux重定向是指修改原来默认的一些东西,对原来系统命令的默认执行方式进行改变,比如说简单的我不想看到在显示器的输出而是希望输出到某一文件中就可以通过Linux重定向来进行这项工作. Linux默认输入 ...
- Freemarker 最简单的例子程序
首先导入包,freemarker.jar 下载地址: freemarker-2.3.18.tar.gz http://cdnetworks-kr-1.dl.sourceforge.net/pro ...
- 从 JDK 源码角度看 Object
Java的Object是所有其他类的父类,从继承的层次来看它就是最顶层根,所以它也是唯一一个没有父类的类.它包含了对象常用的一些方法,比如getClass.hashCode.equals.clone. ...
- Silverlight & Blend动画设计系列七:模糊效果(BlurEffect)与阴影效果(DropShadowEffect)
模糊效果(BlurEffect)与阴影效果(DropShadowEffect)是两个非常实用和常用的两个特效,比如在开发相册中,可以对照片的缩略图添加模糊效果,在放大照片的过程中动态改变照片的大小和模 ...
- springmvc + spring + ibatis + mysql
1.spring mvc 官网下载:https://repo.spring.io/webapp/#/artifacts/browse/simple/General/libs-release-local ...
- 1.http请求编程-->基础原理
一.技术分析 打开网页,不管我们请求的是静态资源还是动态资源,IIS都会根据ISAPI(微软和Process软件公司联合提出的Web服务器上的API标准)这一标准,将请求的文件根据文件后缀名的不同,转 ...
- tomcat启动编码等部署遇到问题
版权声明:本文为博主原创文章,转载请注明文章链接.https://blog.csdn.net/xiaoanzi123/article/details/58254318 2017-02-27 21:01 ...
- Python基础学习总结(四)
6.高阶特性 6.1迭代 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration).在Python中,迭代是通过for ... ...
- 深入理解jQuery插件开发总结(四)
jQuery插件开发模式 软件开发过程中是需要一定的设计模式来指导开发的,有了模式,我们就能更好地组织我们的代码,并且从这些前人总结出来的模式中学到很多好的实践. 根据<jQuery高级编程&g ...