bzoj2091: [Poi2010]The Minima Game DP
生活随笔
收集整理的这篇文章主要介绍了
bzoj2091: [Poi2010]The Minima Game DP
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
2091: [Poi2010]The Minima Game DP
链接
https://www.lydsy.com/JudgeOnline/problem.php?id=2091
思路
这类问题好迷呀。
我们先从小到大sort
先手一定是个后缀。
因为你不能留下大数让对手选呀。
然后后手就在你选择的i前面选([1,i-1])后手及其之后的操作。
f[i]表示前i个里面先手的最大值
f[i]=min(f[i-1],a[i]-f[i-1])
要不这个i点没有贡献,先手是f[i-1],要不就是选这个点,后手是f[i-1]
代码
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=1e6+7; int read() {int x=0,f=1;char s=getchar();for(;s>'9'||s<'0';s=getchar()) if(s=='0') f=-1;for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';return x*f; } int n,a[N]; ll f[N],ans; int main() {n=read();for(int i=1;i<=n;++i) a[i]=read();sort(a+1,a+1+n);for(int i=1;i<=n;++i) f[i]=max(f[i-1],a[i]-f[i-1]);cout<<f[n];return 0; }转载于:https://www.cnblogs.com/dsrdsr/p/10623608.html
总结
以上是生活随笔为你收集整理的bzoj2091: [Poi2010]The Minima Game DP的全部内容,希望文章能够帮你解决所遇到的问题。