(DP) bzoj 2091

【bzoj2091】The Minima Game

Description

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

Input

第一行一个正整数N (N <= 1,000,000),第二行N个正整数(不超过10^9)。

Output

一个正整数,表示最终A与B的分差。

Sample Input

3
1 3 1

Sample Output

2
 
 

排序一下

f[i]表示前i个先手能取到的最大得分差

f[i]=max(f[i-1],a[i]-f[i-1])

就是说 f[i-1]这个决策谁来维持的问题啊。。太神了。。

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

  

原文地址:https://www.cnblogs.com/water-full/p/4521045.html