hdu1176(dp)

17 篇文章 0 订阅

这个题原来做过,昨晚做没做出来,找不到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 0
0 0 0 0 1 1 4 3 3 1 0
0 0 0 0 0 0 0 3 1 1 0
0 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 1
0 0 0 0 1 1 4 3 3 0 1
0 0 0 0 0 0 0 3 1 1 0
0 0 0 0 0 0 0 0 1 0 0
*/
/**
0 0 0 1 1 4 4 4 3 3 0
0 0 0 0 1 1 4 3 3 1 0
0 0 0 0 0 0 0 3 1 1 0
0 0 0 0 0 0 0 0 1 0 0
*/
/**
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 0 1 0 0
*/

/**
0 0 0 1 1 4 4 4 3 3 1
0 0 0 0 1 1 4 3 3 1 1
0 0 0 0 0 0 0 3 1 1 0
0 0 0 0 0 0 0 0 1 0 0
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值