Beans
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2596 accepted submission (s): 1279
Problem descriptionbean-eating is an interesting game, everyone owns an M * n matrix, which is filled with different qualities beans. meantime, there is only one bean in any 1*1 grid. now you want to eat the beans and collect the qualities, but everyone must obey by the following rules: If you eat the bean 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 you eat and then get?
Inputthere are a few cases. in each case, there are two 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 Bean isn't beyond 1000, and 1 <= m * n <= 200000.
Outputfor each case, You 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
Source2009 multi-university training contest 4-host by HDU
Recommendgaojie | we have carefully selected several similar problems for you: 2830 2577 2870 1159
The meaning of this question can be converted to: for each row, there cannot be an interval to take a subsequence, that is, the maximum nonconsecutive subsequence and of the row; then from all the values above, take the maximum nonconsecutive subsequence and; it is equivalent to taking the next row.
Status: F [I] indicates taking the maximum value of the I-th element (a [I] required), and map [I] indicates obtaining a [I] (optional) maximum Value state transfer: F [I] = map [I-2] + A [I]; Map [I] = max {map [I-1], F [I]};
# Include <stdio. h> # include <iostream>Using namespaceSTD;# Define M 200001IntVis[M],Map[M],DP[M],F[M]; IntMax(IntA[], IntN)//Returns the maximum nonconsecutive subsequence sum in. {Int I;F[0] =Map[0] =0;F[1] =Map[1] =A[1]; (I=2;I<=N;I+ +) // Ensure that the I-2 does not cross the array. {F[I] =Map[I-2] +A[I];// Because it is to take an interval, so take a [I], can not take a [I-1], so the maximum value is the maximum number of the first I-2 + A [I]. Map[I] =F[I]>Map[I-1]?F[I]:Map[I-1]; // If a [I] is greater, update the value of map [I.} ReturnMap[N];} Int main (intI, IntJ, IntK) {IntN,M,TOT,Cur; While (Scanf("% D",&N,&M)! =EOF&&N&&M) {(I=1;I<=N;I++) {(J=1;J<=M;J++)Scanf("% D",&Vis[J]);DP[I] =Max(Vis,M);}Printf("% D \ n",Max(DP,N);} Return0;}