标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3418 Accepted Submission(s): 1629
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; const int maxn=211000; int a[maxn]; int dp[maxn],d[maxn],dq[maxn]; int mmax(int a,int b,int c){ int ret; ret=a>b?a:b; return ret>c?ret:c; } int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ int i,j,k; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[j]); } dp[0]=0,dp[1]=a[1]; for(j=2;j<=m;j++){ dp[j]=max(dp[j-2]+a[j],dp[j-1]); } d[i]=dp[m]; } dq[1]=d[1]; for(i=2;i<=n;i++){ dq[i]=max(dq[i-1],dq[i-2]+d[i]); } printf("%d\n",dq[n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chengsheng/p/4515447.html