Test instructions: Take a number in the figure, for example, after taking 81, the same row of adjacent two can not be taken, there are 81 of the above row and the following line can not be taken, asked to get the maximum and how much.
The main point: the maximum value that a row can obtain, and then the maximum value that can be obtained by all rows.
#include <set> #include <map> #include <stack> #include <queue> #include <deque> #include & lt;cmath> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include &
lt;cstring> #include <iostream> #include <algorithm> using namespace std; #define L (i) i<<1 #define R (i) i<<1|1 #define INF 0x3f3f3f3f #define PI ACOs ( -1.0) #define EPS 1e-9 #define M
AXN 200010 #define MOD 1000000007 int DPX[MAXN],DPY[MAXN];
int n,m;
int main () {int t;
scanf ("%d", &t);
while (scanf ("%d%d", &n,&m)! = EOF) {memset (dpx,0,sizeof (DPX));
memset (dpy,0,sizeof (dpy)); for (int i = 2, I <= n+1; i++) {for (int j = 2; J <= M+1; j + +) {int
X
scanf ("%d", &x);
DPX[J] = max (dpx[j-2]+x,dpx[j-1]);
} Dpy[i] = max (dpy[i-2]+dpx[m+1],dpy[i-1]);
}printf ("%d\n", dpy[n+1]);
} return 0;
}