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 次. 解法:后缀数组 ...
随机推荐
- .NET下WebBrowser的一个BUG以及其替代品——geckofx
今天研究一个小问题,在C#的WebBrowser下打开奇艺网的视频,经常整个FLASH就偏了,进度条控制条什么的都没有. 要全屏一下然后还原才能解决这个问题. 如下,图1为webbrowser打开,图 ...
- B1007 [HNOI2008]水平可见直线 几何
其实就是一道很简单的栈,只要明白什么情况会被挡住就行了.假如斜率一样则下面的被挡住,假如不一样就算交点,看那个交点在上面就行了. 题干: Description 在xoy直角坐标平面上有n条直线L1, ...
- 通过usb连接adb
手机不同进入的方式可能不一样,我使用的是努比亚手机. 借鉴这里的:http://adbshell.com/commands/adb-connect 在Wi-Fi上使用ADB:adb connect & ...
- MVVMLight消息通知实现机制详解(一)
最近对委托.事件的订阅使用的太多,订阅与被订阅之间的绑定约束非常...麻烦,所以翻了下MVVMLight源码找出这段可以拿出来用的部分,详情见下: 一.开发中遇到的问题: 场景1:ClassA中存在事 ...
- yii2的form表单用法
使用表单 本章节将介绍如何创建一个从用户那搜集数据的表单页.该页将显示一个包含 name 输入框和 email 输入框的表单.当搜集完这两部分信息后,页面将会显示用户输入的信息. 为了实现这个目标,除 ...
- [Swift通天遁地]七、数据与安全-(15)使用单元测试进行代码的性能分析
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 我的周记1——”云想衣裳花想容"
这里记录过去一周,我学习到的,思考的,看到的,每周五发布. http 网上参考http入门协议 https://juejin.im/post/5afad7f16fb9a07abf72ac30 超文本 ...
- python值函数名的使用以及闭包,迭代器
一.函数名的运用 函数名就是一个变量名,但它是一个特殊的变量名,是一个后面加括号可以执行函数的变量名. def func(): print("我是一个小小的函数") a = fun ...
- Android 使用 Application 简单介绍
Application 配置全局Context 第一步.写一个全局的单例模式的MyApplication继承自Application 覆盖onCreate ,在这个方法里面实例化Application ...
- window.showModalDialog的问题
通过window.showModalDialog的方式弹出B页面,总报“拒绝访问”的错误,将站点添加到受信任站点可以解决这个问题