标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2845
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3097 Accepted Submission(s):
1495
1 #include <cstdio> 2 #include <cmath> 3 #include <iostream> 4 using namespace std; 5 6 int n,m,s; 7 int dpx[222222],dpy[222222]; 8 9 int main () 10 { 11 int i,j,k; 12 while (scanf ("%d%d",&n,&m)==2) 13 { 14 memset(dpx, 0, sizeof(dpx)); 15 memset(dpy, 0, sizeof(dpy));//先对两个数组清零 16 for (i=2; i<=n+1; i++) 17 { 18 for (j=2; j<=m+1; j++) 19 { 20 scanf ("%d",&s); 21 dpx[j] = max(dpx[j-1], dpx[j-2] + s);//每个状态的值等于之前的某个状态加上另一个状态 22 } 23 dpy[i] = max(dpy[i-1], dpy[i-2] + dpx[m+1]);//因为只有加法,dpx[m+1]为每一行的最大值 24 } 25 printf ("%d\n",dpy[n+1]); 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/dxd-success/p/4253825.html