[Game DP] BZOJ1783: [Usaco2010 jan]taking turns__ Other

Source: Internet
Author: User

This game is relatively simple, each person's goal is only to let their own points more. So direct DP DP Request:
Set fi,0 f_{i,0} to represent the first pick from I I, the best value of the upper tempo. fi,1 f_{i,1} is the optimal value of a.
Obviously there are fi,0=max{aj+fj+1,1} f_{i,0}=max\{a_j+f_{j+1,1}\}, fi,1=fpos,0 f_{i,1}=f_{pos,0}. Pos POS indicates where the fi,0 f_{i,0} is transferred from.

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=700015;
typedef long long LL;
int N,A[MAXN];
LL f[maxn][2];
int main () {
    freopen ("bzoj1783.in", "R", stdin);
    Freopen ("Bzoj1783.out", "w", stdout);
    scanf ("%d", &n);
    for (int i=1;i<=n;i++) scanf ("%d", &a[i]);
    int pos=n+1; 
    for (int i=n;i>=1;i--) {
        if (a[i]+f[i+1][1]>=a[pos]+f[pos+1][1]) pos=i;
        F[I][0]=A[POS]+F[POS+1][1];
        F[I][1]=F[POS+1][0];
    }
    printf ("%lld%lld\n", f[1][0],f[1][1]);
    return 0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.