hdu1176(dp),hdu1176dp

來源:互聯網
上載者:User

hdu1176(dp),hdu1176dp

這個題原來做過,昨晚做沒做出來,找不到bug,感覺很難找

今天又打了一遍,耐心的輸出一些資料,bug很容易就出來了。

切記浮躁,做不出就放一放,沒必要只為做對而刷題,要感受一點一點的提高。

總之就是越慢越好。



開=開始是這樣

if( a[i+1][j]>=a[i+1][j+1]&&a[i+1][j]>=a[i+1][j-1]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j];           else if( a[i+1][j-1]>=a[i+1][j+1]&&a[i+1][j-1]>=a[i+1][j]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j-1];           else if( a[i+1][j+1]>=a[i+1][j]&&a[i+1][j+1]>=a[i+1][j-1]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j+1];
雖然注意到兩邊的情況,直接跳過了,沒管,資料就是這樣的。

0 0 0 1 1 4 4 4 3 3 00 0 0 0 1 1 4 3 3 1 00 0 0 0 0 0 0 3 1 1 00 0 0 0 0 0 0 0 1 0 0

ac:

#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>using namespace std;int a[100000+5][12];int Max(int  a,int b,int  c){     if(a>=b&&a>=c) return a;    else if(b>=a&&b>=c) return b;    else if(c>=a&&c>=b) return c;}int main(){    int n;    while(scanf("%d",&n)&&n){        memset(a,0,sizeof(a));        int maxx=0;        while(n--){           int x,y;            scanf("%d%d",&x,&y);            a[y][x]++;            if(y>maxx) maxx=y;        }for(int i=maxx-1;i>=0; i--){        for(int j=0;j<11;j++)       {            if(j==0) a[i][j]+=max(a[i+1][j],a[i+1][j+1]);            else if(j==10) a[i][j]+=max(a[i+1][j],a[i+1][j-1]);            else a[i][j]+=Max( a[i+1][j], a[i+1][j-1], a[i+1][j+1] );//           else if( a[i+1][j]>=a[i+1][j+1]&&a[i+1][j]>=a[i+1][j-1]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j];//           else if( a[i+1][j-1]>=a[i+1][j+1]&&a[i+1][j-1]>=a[i+1][j]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j-1];//           else if( a[i+1][j+1]>=a[i+1][j]&&a[i+1][j+1]>=a[i+1][j-1]&&j+1<11&&j-1>=0) a[i][j]+=a[i+1][j+1];       }    }//        for(int i=maxx-1;i>=0;i--)//        for(int j=0;j<=10;j++){//            if(j==0) a[i][j]+=max(a[i+1][j],a[i+1][j+1]);//            else if(j==10) a[i][j]+=max(a[i+1][j],a[i+1][j-1]);//            else a[i][j]+=Max( a[i+1][j], a[i+1][j-1], a[i+1][j+1] );//        }//        for(int i=0;i<=maxx;i++){//            for(int j=0;j<=10;j++)//            printf("%d ",a[i][j]);//            printf("\n");//        }        printf("%d\n",a[0][5]);    }    return 0;}/**0 0 0 1 1 4 4 4 0 3 10 0 0 0 1 1 4 3 3 0 10 0 0 0 0 0 0 3 1 1 00 0 0 0 0 0 0 0 1 0 0*//**0 0 0 1 1 4 4 4 3 3 00 0 0 0 1 1 4 3 3 1 00 0 0 0 0 0 0 3 1 1 00 0 0 0 0 0 0 0 1 0 0*//**0 0 0 0 0 0 0 0 0 0 00 0 0 0 1 1 1 0 0 0 00 0 0 0 0 0 0 2 0 0 00 0 0 0 0 0 0 0 1 0 0*//**0 0 0 1 1 4 4 4 3 3 10 0 0 0 1 1 4 3 3 1 10 0 0 0 0 0 0 3 1 1 00 0 0 0 0 0 0 0 1 0 0*/


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.