2017沈阳网络赛hdu6199 gems gems gems
gems gems gems
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
(1≤T≤10
), the number of the test cases.
For each test case:
the first line
contains a numbers n
(1≤n≤20000
);
the second line contains n numbers: V1
,V
2
…V
n
. (−100000≤Vi
≤100000
)
the difference between the total value of gems Alice took and the total value of
gems Bob took.
3
1 3 2
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls (rt<<1)
#define rs (rt<<1|1)
#define all(x) x.begin(),x.end()
const int maxn=2e4+;
const int N=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qmul(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=(f+p)%mo;p=(p+p)%mo;q>>=;}return f;}
ll qpow(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=f*p%mo;p=p*p%mo;q>>=;}return f;}
int n,m,k,t,a[maxn],dp[maxn][],sum[maxn];
void upd(int &x,int y){if(x<y)x=y;}
int main(){
int i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]),sum[i]=sum[i-]+a[i];
int ret=-inf;
for(i=n;i>=;i--)
{
for(j=min(,n-i+);j>=;j--)
{
dp[i][j]=sum[i+j-]-sum[i-];
if(n-i-j+>=j)
{
int re=dp[i+j][j];
if(n-i-j>=j)upd(re,dp[i+j][j+]);
dp[i][j]-=re;
}
if(i==&&j<=)upd(ret,dp[i][j]);
}
}
printf("%d\n",ret);
}
return ;
}
/*
1
7
68 -1 25 59 -65 -46 -28
ans:112
*/
2017沈阳网络赛hdu6199 gems gems gems的更多相关文章
- HDU 6200 2017沈阳网络赛 树上区间更新,求和
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边 ...
- HDU 6199 2017沈阳网络赛 DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1 ...
- HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...
- HDU 6205 2017沈阳网络赛 思维题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...
- HDU 6198 2017沈阳网络赛 线形递推
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6198 题意:给出一个数k,问用k个斐波那契数相加,得不到的数最小是几. 解法:先暴力打表看看有没有规律 ...
- HDU 6201 2017沈阳网络赛 树形DP或者SPFA最长路
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6201 题意:给出一棵树,每个点有一个权值,代表商品的售价,树上每一条边上也有一个权值,代表从这条边经过 ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- HDU 6195 2017沈阳网络赛 公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6195 题意:有M个格子,有K个物品.我们希望在格子与物品之间连数量尽可能少的边,使得——不论是选出M个 ...
- HDU 6194 string string string 2017沈阳网络赛 后缀数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6194 题意:告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次. 解法:后缀数组 ...
随机推荐
- 【Codevs1322】单词矩阵
Position: http://codevs.cn/problem/1322/ List Codevs1322 单词矩阵 List Description Input Output Sample I ...
- jsp整合discuz
转自:http://blog.sina.com.cn/s/blog_49298ed001000a99.html 最近在实验室做项目用到的一个东西,拿来介绍一下. 需求:现有行业应用 ...
- bzoj3629 [JLOI2014]聪明的燕姿——DFS+约数和定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 扫除了一个知识盲点:约数和定理 约数和定理: 对于一个大于1正整数n可以分解质因数:n ...
- 65. ExtJs获取文本框中值的几种方式
转自:https://blog.csdn.net/qiu512300471/article/details/17415675/ 1.Html文本框 如:<input type=" ...
- window.onload的使用
window.onload:当页面加载的时候可以调用某些函数 例如: 1.最简单的调用方式 直接写到html的body标签里面,如: <html> <body onload=&quo ...
- [Swift通天遁地]二、表格表单-(12)设置表单文字对齐方式以及自适应高度的文本区域TextArea
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Eclipse设置空格代替tab
1.点击 window->preference-,依次选择 General->Editors->Text Editors,选中右侧的 insert space for tabs;如下 ...
- 详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统)、模糊查询
详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统).模糊查询 1,创建数据库,我的用户名:root 密码:root,数据库名称:lianwei,表名:login 2,效果 ...
- Tempter of the Bone------剪枝
看了好多别人的 代码,最终还是 感觉 这种代码的风格适合我 下面附上代码 /* 首先 应该充满信心! 先写出来 自己的程序 然后慢慢改 , 如果是 答题思路错误的话 借鉴别人的 代码 再写 */ ...
- Comet OJ - Contest #3 题解
传送门 太菜了连\(D\)都做不出来没有小裙子\(QAQ\) \(A\) 暴力把所有的数对都算出来,然后\(sort\)一下就行了 const int N=505; int a[N],st[N*N], ...