# NOIP2014 Flying Bird "DP"

Source: Internet
Author: User
Tags stdin
Description

Flappy Bird is a rage casual mobile phone game. Players need to constantly control the frequency of clicking on the phone screen to adjust the bird's flight altitude, so that the bird smoothly through the screen to the right of the pipe gap. If a bird accidentally hits a water pipe or falls on the ground, it will fail.

To simplify the problem, we have simplified and adapted the rules of the game: The game interface is a two-dimensional plane with a length of nn and a height of mm, with a KK pipe (ignoring the width of the pipe). The bird always moves within the game's interface. The bird starts at the leftmost integer height of the game interface and reaches the far right of the game interface, completing the game. Birds each unit time along the horizontal axis to the right of the distance is 11, vertical movement of the distance is controlled by the player. If you click on the screen, the bird will rise a certain height of XX, each unit time can be clicked multiple times, effect overlay; If you do not tap the screen, the bird will drop a certain height YY. When the birds are located in different positions in the horizontal axis, the height of the ascending XX and the descent may vary. The bird height is equal to 00 or the bird hits the pipe and the game fails. When the bird height is mm, it can no longer rise.

Now, tell me if you can finish the game. If you can, output a minimum number of hits on the screen, otherwise, the output bird can pass the maximum number of pipe gaps. Solving

The

definition F[i][j] f[i][j] represents the optimal solution for flying to (I,J) (i,j), so it's easy to think of a violent transfer: enumerates a few screens in the previous second. The complexity of this is O (n3) O (n^3). Consider optimized transfer, f[i][j]=min (f[i−1][j−k∗up[i−1]]+k), F[i][j−up[i−1]]=min (F[i−1][j− (k+1) ∗up[i−1]]+k) f[i][j]=min (f[i-1][j-k *UP[I-1]]+K); F[i][j-up[i-1]]=min (f[i-1][j-(k+1) *up[i-1]]+k) | k=1,2,3 ... k=1,2,3., can be found, F[i][j]=min (f[i−1][j−up[i−1]],f[i][j−up[i−1]) +1 f[i][j]=min (f[i-1][j-up[i-1]],f[i][j-up[i-1 ]]) +1; a little attention to the border. Code

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 10006 #define MAXM 1006 using
namespace Std;
    Inline char NC () {static Char buf[100000],*i=buf,*j=buf; Return i==j&& (j= (i=buf) +fread (Buf,1,100000,stdin), i==j)?
eof:*i++;
    } inline int _read () {char ch=nc (); int sum=0; while (!) (
    ch>= ' 0 ' &&ch<= ' 9 ')) Ch=nc ();
    while (ch>= ' 0 ' &&ch<= ' 9 ') sum=sum*10+ch-48,ch=nc ();
return sum;
} int N,M,K,ANS,U[MAXN],D[MAXN],UP[MAXN],DN[MAXN],F[MAXN][MAXM];
    int main () {freopen ("bird.in", "R", stdin);
    Freopen ("Bird.out", "w", stdout);
    memset (d,0,sizeof (D)); Memset (U,63,sizeof (U)); int inf=u[0]; N=_read (); M=_read ();
    K=_read ();
    for (int i=0;i<n;i++) Up[i]=_read (), Dn[i]=_read ();
    for (int i=1,x;i<=k;i++) X=_read (), D[x]=_read (), U[x]=_read ();
    memset (F,63,sizeof (f));
    for (int i=1;i<=m;i++) f[0][i]=0; for (int i=1;i<=n;i++) {for (int j=up[i-1];j<=m;j++) f[i][j]=min (f[i][j-up[i-1]],f[i-1][j-up[i-1]]) +1;
        for (int j=m-up[i-1];j<=m;j++) f[i][m]=min (F[i][m],min (f[i][j],f[i-1][j]) +1);
        for (int j=1;j<=m-dn[i-1];j++) f[i][j]=min (f[i][j],f[i-1][j+dn[i-1]); for (int j=1;j<=m;j++) if (j<=d[i]| |
    J>=u[i]) F[i][j]=inf;
    } Ans=inf;
    for (int i=1;i<=m;i++) ans=min (Ans,f[n][i]);
        if (ans==inf) {printf ("0\n");
        ans=0;
        for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (f[i][j]<inf) {ans=i;break;}
        int ans0=0;
        for (int i=1;i<=ans;i++) if (u[i]<inf) ans0++;
    printf ("%d\n", ANS0);
    }else printf ("1\n%d\n", ans);
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.