您的位置:首页 > 其它

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


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: