[luogu p3507] [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
给定一个长度为
考虑到题目中要求最小值,而排序不会影响答案,数据范围也支持我们排序。那就先排个序。
接下来说的
先考虑双方的博弈策略:一定拿从大到小连续的一段数,也就是一定拿的是
为什么?
因为如果你连
考虑 dp。定义
什么意思呢?
这个做法 主要分数不美丽,不然暴力最美
方便叙述,把
观察到
到这里还能理解吗?不能理解就多看看吧!相信你可以看懂。
最后把
因为排序。
状态转移是
/*
* @Author: crab-in-the-northeast
* @Date: 2022-04-06 23:23:22
* @Last Modified by: crab-in-the-northeast
* @Last Modified time: 2022-04-06 23:30:39
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
inline int read() {
int x = 0;
bool flag = true;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
flag = false;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
if (flag)
return x;
return ~(x - 1);
}
const int maxn = 1000005;
int a[maxn], f[maxn];
int main() {
int n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
std :: sort(a + 1, a + 1 + n);
f[1] = a[1];
for (int i = 2; i <= n; ++i)
f[i] = std :: max(f[i - 1], a[i] - f[i - 1]);
printf("%d\n", f[n]);
return 0;
}
不错的dp!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】