题目描述

Alice and Bob learned the minima game, which they like very much, recently.

The rules of the game are as follows.

A certain number of cards lies on a table, each inscribed with a positive integer.

The players make alternate moves, Alice making the first one.

A move consists in picking an arbitrary positive number of cards from the table.

For such move the player receives a number of points equal to the minimum of the numbers inscribed on the cards he collected.

The game ends when the last card is removed from the table.

The goal of each player is maximizing the difference between their and their opponent's score.

Alice and Bob have duly noted that there is an optimal strategy in the game.

Thus they are asking you to write a program that, for a given set of cards, determines the outcome of the game when both players play optimally.

给出N个正整数,AB两个人轮流取数,A先取。每次可以取任意多个数,直到N个数都被取走。每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大。在这样的情况下,最终A的得分减去B的得分为多少。

输入输出格式

输入格式:

In the first line of the standard input there is one integer () given, denoting the number of cards.

The second line holds positive integers (), separated by single spaces, that are inscribed on the cards.

输出格式:

Your program should print out a single line with a single integer to the standard output - the number of points by which Alice wins over Bob, assuming they both play optimally; if it is Bob who has more points, the result should be negative.

输入输出样例

输入样例#1:

3
1 3 1

输出样例#1:

2

思路:如果选了i,那么>=i的数都要选。否则对方一定会更优。因为假如选完>=i的数的状态为s1,没选完的为s2。对方可以先选完>=i的数,那么他接下来面对的状态就是s1了。所有在s2下,一切s1有的决策他都能选择。同时他还多了一些决策。所有s2下他一定比s1优。所以我们先将n个数从小到大排序。f[i]表示剩下了1..i这个前缀的max(先手-后手)。枚举先手决策,f[i]=max(a[j]-f[j-1])。

代码:

#include<cstdio>
#include<algorithm>
#define maxn 1000007
using namespace std;
int n,f[maxn],a[maxn];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=1;i<=n;++i)
f[i]=max(f[i-1],a[i]-f[i-1]);
printf("%d\n",f[n]);
return 0;
}

最新文章

  1. XSS 前端防火墙 —— 整装待发
  2. webform内置对象
  3. Shrink磁盘
  4. 根据IP定位获取城市代码
  5. 学习总结 for循环--冒泡排序
  6. open/fopen read/fread write/fwrite区别
  7. SQL创建函数及应用
  8. 【HDU 4276】The Ghost Blows Light(树形DP,依赖背包)
  9. 使用 Eclipse 的 SVN 主要插件创建项目/支/标签
  10. C#利用Emit反射实现AOP,以及平台化框架封装思路
  11. druid查询
  12. 干了这杯Java之ArrayList
  13. USB协议基础知识笔记
  14. ipmitool 工具使用
  15. bzoj 1008
  16. js获取子节点和修改input的文本框内容
  17. java mina框架使用
  18. c++ boost 苹果内购 IAP验证
  19. BZOJ4766:文艺计算姬(矩阵树定理)
  20. Javascript 身份证号获得出生日期、获得性别、检查身份证号码

热门文章

  1. python(时间模块,序列化模块等)
  2. java反射专题二
  3. 10-24C#基础--枚举
  4. hibernate学习笔记(4)表单操作
  5. VS2012新建网站出现(1)的解决方案
  6. xUtils 源码解析
  7. C++面向对象类的实例题目三
  8. WordCountPro 编码与测试
  9. 有三个线程,a、b、c,a打印“T1”,b打印“T2”,c打印“T3”,a执行完后,b执行;b执行完后,c执行。如此循环100遍
  10. 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(一)