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 次. 解法:后缀数组 ...
随机推荐
- Mysql的简单使用(一)
如果你会查询这些相关的问题,说明你是一个正在或者准备从事IT的程序猿,对于一个程序猿而言,不会使用linux系统的程序猿不是一好的程序猿哦!因为windows有时候真的让人很抓狂,而本人也相信没有什么 ...
- 【POJ 1995】 Raising Modulo Numbers
[题目链接] http://poj.org/problem?id=1995 [算法] 快速幂 [代码] #include <algorithm> #include <bitset&g ...
- PCB genesis孔符制作实现方法
一.先看genesis原始孔符 孔符的作用:用于表示孔径的大小的一种代号, 当孔径检测时,可以按分孔图中的孔符对应的孔径尺寸对孔径检测. 在实际PCB行业通常不使用原始(图形)孔符,而使用字母孔符(如 ...
- [App Store Connect帮助]二、 添加、编辑和删除用户(6)生成 API 密钥
如果已批准您访问 App Store Connect API,您可以生成 API 密钥,以便使用该密钥配置.认证和使用 App Store Connect 服务. 有关管理和保护您密钥的更多信息,请参 ...
- python django简单操作
准备: pip3 install django==1.10.3 cmd django-admin startproject guest 创建一个guest的项目 cd guest manage. ...
- BZOJ 2946 SA/SAM
思路: 1. 二分+后缀数组 2.SAM //By SiriusRen #include <cstdio> #include <cstring> #include <al ...
- C/C++ Python的函数默认参数
发现C/C++ Python的函数可以使用默认参数,来减少传参时候的参数个数. 但是:这样的默认参数最好是不变对象! #include <stdio.h> #include <st ...
- Java—break跳出语句
在开发代码时,常常会产生这样的疑惑:break跳出语句是如何应用的呢? 使用break的场景有两种:一.switch语句中.二.循环语句. 这里就不介绍switch语句,主要说一下break在循环中的 ...
- brew update失败提示:/System/Library/Frameworks/Ruby.framework/的解决方法
本文由@ray 出品,转载请注明出处. 文章链接:http://www.cnblogs.com/wolfray/p/8040701.html 想用brew安装wget,但是提示失败,然后想先 bre ...
- Android studio 中R.menu的创建
对于Android开发中的menu没有声明的情况: 首先,将鼠标定位到红色的menu上面, 然后,Alt+enter组合键,建立文件menu, 然后将以下代码复制进去: <item androi ...