HDU 2845 Beans
Beans
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1433 Accepted Submission(s): 741
Now, how much qualities can you eat and then get ?
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int dp[2003][2003];
int rc[2003];
int main()
{
int n,m;
int i,j;
int Max;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&dp[i][j]);
for(i=1;i<=n;i++)
{ rc[0]=-100000000;
rc[1]=Max=dp[i][1];
for(j=2;j<=m;j++)
{
rc[j]=max(max(rc[j-2]+dp[i][j],dp[i][j]),rc[j-2]);
rc[j]=max(rc[j],rc[j-1]);//开始写的时候少了这个
Max=Max>rc[j]?Max:rc[j];
}
dp[i][0]=Max;
}
rc[0]=-100000000;
rc[1]=Max=dp[1][0];//方程写对后,rc[1]忘记赋值,又一次WA
for(i=2;i<=n;i++)
{
rc[i]=max(max(rc[i-2]+dp[i][0],dp[i][0]),rc[i-2]);
rc[i]=max(rc[i],rc[i-1]);
Max=Max>rc[i]?Max:rc[i];
}
printf("%d\n",Max);
}
return 0;
}