HDU 2845 Beans(dp)

来源:互联网 发布:远程监控软件 编辑:程序博客网 时间:2024/05/16 06:43

这题目思路是对的,但是自己写死活写不对,代码太粗糙了,在网上看到这个代码很有技巧性,就贴过来了。

思路是想出来了,但编码技巧还得提高啊,细节处理实在太差了。

////  main.cpp//  Richard////  Created by 邵金杰 on 16/9/13.//  Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=200000+10;int dp1[maxn],dp2[maxn];int main(){    int n,m;    while(scanf("%d%d",&n,&m)!=EOF)    {        memset(dp1,0,sizeof(dp1));        memset(dp2,0,sizeof(dp2));        int s;        for(int i=2;i<=n+1;i++){            for(int j=2;j<=m+1;j++){                scanf("%d",&s);                dp1[j]=max(dp1[j-1],dp1[j-2]+s);            }            dp2[i]=max(dp2[i-1],dp2[i-2]+dp1[m+1]);        }        cout<<dp2[n+1]<<endl;    }    return 0;}



0 0
原创粉丝点击