2091: [Poi2010]The Minima Game
2024-10-20 05:27:29
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 ;
}
最新文章
- DevExpress TreeList 全选和反选 z
- EF框架step by step(4)—DBcontext应用于已存在数据库
- MATLAB 编程风格指南及注意事项
- uva--1339 - Ancient Cipher(模拟水体系列)
- 数据对象ajax学习篇9
- Ural1057 - Amount of Degrees(数位DP)
- Crystal Report分組中的序號重新遞增
- chroot_local_user和chroot_list_enable含义
- c++,命名空间(namespace)
- OC--类型为ID 的类的名称
- RESTful_简介
- Moonlight Shadow
- 谷歌排名影响因素最新研究(SEM RUSH版)
- Java I/O输入输出流
- Mvc 提交表单的4种方法
- 100-days: twenty-three
- class文件魔数CAFEBABE的由来
- k8s 1.12.6版的kubeadm默认配置文件
- Vue项目在真机测试
- 树莓派3代b型静态IP设置,和ssh的wlan配置
热门文章
- jmeter利用自身代理录制脚本
- 洗礼灵魂,修炼python(23)--自定义函数(4)—闭包进阶问题—>;报错UnboundLocalError: local variable &#39;x&#39; referenced before assignment
- 找Maven -->; pom.xml -->; groupId和artifactId的网站
- 【PAT】B1054 求平均值(20 分)
- NOIP2018 AFO记
- 【BZOJ4946】[NOI2017]蔬菜(贪心)
- Android的进阶学习(六)--理解View事件分发
- HTML和CSS实现左侧固定宽度右侧内容可滚动
- js获得当前元素的样式
- POJ1419 Graph Coloring