Problem Descriptionbean-eating is a interesting game, everyone owns an m*n matrix, which are filled with different qualiti Es beans. Meantime, there is the only one bean in any 1*1 grid. Now your want to eat the beans and collect the qualities, but everyone must obey by the following rules:if you eat the BEA n at the coordinate (x, y), you can ' t eat the beans anyway at the coordinates listed (if exiting): (x, Y-1), (x, y+1), and The both rows whose Abscissas are x-1 and x+1.
Now, how much qualities can do you eat and then get?
Inputthere is a few cases. In each case, there is the integer M (row number) and N (column number). The next M lines each contain N integers, representing the qualities of the beans. We can make sure that the quality of beans isn ' t beyond, and 1<=m*n<=200000.
Outputfor the just output the MAX qualities you can eat and then get.
Sample Input
4 611 0 7 5 13 978 4 81 6 22 41 40 9 34 16 1011 22 0 33 39 6
Sample Output
242
Source
Field=problem&key=2009+multi-university+training+contest+4+-+host+by+hdu&source=1&searchmode= SOURCE ">2009 multi-university Training Contest 4-host by HDU
Idea: Pay attention to the state transition equation. There is also the similarity of the transfer equation and the column of the row. And note that the array is bigger.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace STD; #define N 200005int Dpx[n],dpy[n];int Main () { int n,m,i,j,s; while (~SCANF ("%d%d", &n,&m)) { memset (dpx,0,sizeof (DPX)); memset (dpy,0,sizeof (dpy)); for (i=2;i<=n+1;i++) { //memset (dpy,0,sizeof (dpy)); Why this can be stared out, because it will be overwritten for (j=2;j<=m+1;j++) { scanf ("%d", &s); Dpy[j]=max (dpy[j-1],dpy[j-2]+s); Dpy represents the largest number and } Dpx[i]=max (Dpx[i-1],dpx[i-2]+dpy[1+m]) that the row can fetch from left to right; DPX represents the largest and } printf ("%d\n", Dpx[n+1]) from which the number can be taken from the above line; } return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
HDU 2845 Beans (DP)