2091: [Poi2010]The Minima Game

链接

分析:

  首先排序后,一定是选的连续的一段。

  f[i]表示前i个位置,先手-后手的最大得分。

  那么考虑第i个位置是否选,如果选,先手选的就是从i开始到i的一段,后手在1到i-1就变成了先手,所以就是a[i]-f[i-1]。

  否则第i个位置不选,直接从i-1转移即可。

代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
LL a[N], dp[N]; int main() {
int n = read();
for (int i = ; i <= n; ++i) a[i] = read();
sort(a + , a + n + );
LL mx = , mn = 1e18;
dp[] = a[];
for (int i = ; i <= n; ++i) {
dp[i] = max(dp[i - ], a[i] - dp[i - ]);
}
cout << dp[n];
return ;
}

2091: [Poi2010]The Minima Game的更多相关文章

  1. BZOJ 2091: [Poi2010]The Minima Game

    Description 每次可以任取数字,使用最优策略让差最大. Sol DP. 一开始我写了个单调队列贪心,然后狂WA不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...

  2. bzoj 2091: [Poi2010]The Minima Game【博弈论+贪心+dp】

    不知道算不算博弈 很妙的贪心,一直在想SG函数结果... 首先从大到小排个序,然后考虑当前的人要怎么选:如果不选最后一段,那么另一人会选,这样不利于当前的人,所以每个人一定会选最后一段 设f[i]为要 ...

  3. BZOJ 2091: [Poi2010]The Minima Game 博弈dp

    十分有趣的问题. 我们发现如果拿的话肯定要先拿一些大的. 所以我们可以先将所有数从小到大排序,令 $f[i]$ 表示拿完前 $i$ 小先手-后手的最大值. 则有转移:$f[i]=max(f[i-1], ...

  4. BZOJ2091: [Poi2010]The Minima Game

    2091: [Poi2010]The Minima Game Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 243  Solved: 163[Subm ...

  5. bzoj2091: [Poi2010]The Minima Game DP

    2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...

  6. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  7. [bzoj2091][Poi2010]The Minima Game_动态规划

    The Minima Game bzoj-2091 Poi-2010 题目大意:给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值, ...

  8. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  9. P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

随机推荐

  1. LeetCode题解之 Subtree of Another Tree

    1.题目描述 2.问题分析 判断一个节点,然后判断子树. 3.代码 bool isSubtree(TreeNode* s, TreeNode* t) { if (s == NULL) return f ...

  2. 洗礼灵魂,修炼python(56)--爬虫篇—知识补充—编码之url编码

    其实在最前面的某一篇博文里,是绝对提过编码的,有ASCII,有UTF-8,有GB2312等等,这些我绝对说过的. url编码 首先,Http协议中参数的传输是"key=value" ...

  3. gcc库链接

    转载于https://blog.csdn.net/zhangdaisylove/article/details/45721667 1.库的分类 库有静态库和动态库,linux下静态库为.a,动态库为. ...

  4. margin auto 实现居中,与text-align:center的区别

    本文导读:一个元素在水平方向上所占的长度,由width ,padding ,和margin 决定.这些值中,只有width和margin-left,margin-right可以设为auto,text- ...

  5. 离线安装Cloudera Manager 5和CDH5(最新版5.9.3) 完全教程(七)界面安装

    一.安装过程 1.1 登录 1.2 接受许可协议 1.3 选择免费版本 1.4 选择下一步 1.5 选择当前管理的主机 1.6 选择使用Parcel安装,选择CDH版本,点击继续 1.7 等待安装 此 ...

  6. Java集合实现类区别与联系

    ArrayList和LinkList相同点和区别: 共性: 都实现了List接口,都是list的实现类,处理list集合操作. 区别: ArrayList:底层存储结构是数组,每个元素都有index标 ...

  7. mybatis基础系列(四)——关联查询、延迟加载、一级缓存与二级缓存

    关本文是Mybatis基础系列的第四篇文章,点击下面链接可以查看前面的文章: mybatis基础系列(三)——动态sql mybatis基础系列(二)——基础语法.别名.输入映射.输出映射 mybat ...

  8. Java不定参数Object… obj 和 Object[] 的区别

    Java不定参数Object… obj 和 Object[] 的区别 简述: java中方法重载可以实现参数不同自动匹配对应方法.但现实中也存在这种问题.普通传参对于形如下面的方法,却显得臃肿而失优雅 ...

  9. PAT A1029 Median (25 分)——队列

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  10. python基础学习第二天

    读文件 r 要以读文件的模式打开一个文件对象,使用Python内置的open()函数,传入文件名和标示符 写文件 w 写文件和读文件是一样的,唯一区别是调用open()函数时,传入标识符’w’或者’w ...