NYOJ 234 吃土豆
2014-07-16 09:54
381 查看
[b]吃土豆[/b]
时间限制:1000ms|内存限制:65535KB难度:4
[b]描述[/b]Bean-eatingisaninterestinggame,everyoneownsanM*Nmatrix,whichisfilledwithdifferentqualitiesbeans.Meantime,thereisonlyonebeaninany1*1grid.Nowyouwanttoeatthebeansandcollectthequalities,buteveryonemustobeybythefollowingrules:ifyoueatthebeanatthecoordinate(x,y),youcan’teatthebeansanywayatthecoordinateslisted(ifexiting):(x,y-1),(x,y+1),andthebothrowswhoseabscissasarex-1andx+1.
#include<iostream> #include<cstdio> #include<cstring> #include<climits> usingnamespacestd; intd[510][510],dp[510][2]; intmx[510]; intmain(){ intr,c,i,j,temp,ans; while(~scanf("%d%d",&r,&c)){ for(i=1;i<=r;i++){ memset(dp,0,sizeof(dp)); mx[i]=INT_MIN; for(j=1;j<=c;j++){ scanf("%d",d[i]+j); dp[j][0]=max(dp[j-1][0],dp[j-1][1]); dp[j][1]=dp[j-1][0]+d[i][j]; temp=max(dp[j][0],dp[j][1]); mx[i]=max(temp,mx[i]); } } memset(dp,0,sizeof(dp)); ans=INT_MIN; for(i=1;i<=r;i++){ dp[i][0]=max(dp[i-1][0],dp[i-1][1]); dp[i][1]=dp[i-1][0]+mx[i]; temp=max(dp[i][0],dp[i][1]); if(temp>ans)ans=temp; } printf("%d\n",ans); } return0; }
ViewCode
相关文章推荐
- nyoj234 吃土豆 01背包
- NYOJ 题目234 吃土豆
- nyoj-动态规划-234-吃土豆-201308131021
- NYOJ 234 吃土豆(基础dp)
- NYOJ-234 吃土豆
- nyoj 234 吃土豆
- NYOJ_234_吃土豆
- NYOJ-234-DP(吃土豆)
- nyoj-234-吃土豆(动态规划)
- nyoj 吃土豆 234 (双层DP)
- 吃土豆_nyoj_234(动态规划).java
- NYOJ234吃土豆(双层动态规划)
- NYOJ234吃土豆
- nyoj 234 吃土豆
- NYOJ234-吃土豆(双层DP)
- NYOJ 234 吃土豆
- Nyoj 234 吃土豆
- hdu-Beans(动态规划,nyoj-234-吃土豆)
- nyoj 234 吃土豆
- NYOJ 吃土豆(动态规划)