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 ;
}

最新文章

  1. DevExpress TreeList 全选和反选 z
  2. EF框架step by step(4)—DBcontext应用于已存在数据库
  3. MATLAB 编程风格指南及注意事项
  4. uva--1339 - Ancient Cipher(模拟水体系列)
  5. 数据对象ajax学习篇9
  6. Ural1057 - Amount of Degrees(数位DP)
  7. Crystal Report分組中的序號重新遞增
  8. chroot_local_user和chroot_list_enable含义
  9. c++,命名空间(namespace)
  10. OC--类型为ID 的类的名称
  11. RESTful_简介
  12. Moonlight Shadow
  13. 谷歌排名影响因素最新研究(SEM RUSH版)
  14. Java I/O输入输出流
  15. Mvc 提交表单的4种方法
  16. 100-days: twenty-three
  17. class文件魔数CAFEBABE的由来
  18. k8s 1.12.6版的kubeadm默认配置文件
  19. Vue项目在真机测试
  20. 树莓派3代b型静态IP设置,和ssh的wlan配置

热门文章

  1. jmeter利用自身代理录制脚本
  2. 洗礼灵魂,修炼python(23)--自定义函数(4)—闭包进阶问题—&gt;报错UnboundLocalError: local variable &#39;x&#39; referenced before assignment
  3. 找Maven --&gt; pom.xml --&gt; groupId和artifactId的网站
  4. 【PAT】B1054 求平均值(20 分)
  5. NOIP2018 AFO记
  6. 【BZOJ4946】[NOI2017]蔬菜(贪心)
  7. Android的进阶学习(六)--理解View事件分发
  8. HTML和CSS实现左侧固定宽度右侧内容可滚动
  9. js获得当前元素的样式
  10. POJ1419 Graph Coloring