There are 5 bricks... with an empty one, there are 6 states... so it is obvious that you can use a 6-digit status DP...
But in this case, I think I have optimized all of the optimizations... or time-out... I think the data range is 100*6... the table is first AC ..
I think my DP is still quite superficial ~~
# Include <iostream> # include <stdio. h> # include <string. h> # include <set> # include <algorithm> # include <cmath> # define oo 1000000007 # define ll long # define pi acos (-1.0) # define MAXN 505 using namespace std; int sharp [6] [6] [2] ={{ 0, 0}, {0}, {0, 0}, {0, 0 }, {}},{ {0 0}, {}, {-1,-1 }, {}, {0, 0}, {}, {-1,-1 }}, {0, 0}, {0, 1}, {0, 0}, {-1,-1 }}, {0, 0}, {0, 1}, {132}, {132}, {-1,-1 }}; int n, m, canuse [132], w [], tall [], dp [101] [132] [132], num, step [6] = {132, 132, 4, 4}; bool f [] [] [2]; bool legal (int x) // determines if this row is valid {int I, j, t = x, a [10] [10]; memset (a, 0, sizeof (a); w [num + 1] = 0; for (I = 1; I <= m; I ++) {if (I + 1> m & (x % 6 = 1 | x % 6 = 5) return false; if (I + 2> m & (x % 6 = 2 | x % 6 = 3 | x % 6 = 4) return false; for (j = 0; j <step [x % 6]; j ++) a [sharp [x % 6] [j] [0] [I + sharp [x % 6] [j] [1]-1] ++; w [num + 1] + = step [x % 6]; x/= 6 ;} for (I = 0; I <10; I ++) for (j = 0; j <10; j ++) if (a [I] [j]> 1) return false; tall [num + 1] = 0; for (I = 1; I <= m; I ++) {if (t % 6 = 1 | t % 6 = 2 | t % 6 = 5) tall [num + 1] = 2; else if (t % 6! = 0 & tall [num + 1] <1) tall [num + 1] = 1; t/= 6;} return true;} bool OK (int, int B, int tp) // determine whether a conflict exists. {int I, j, h [10] [10]; a = canuse [a], B = canuse [B]; memset (h, 0, sizeof (h); for (I = 1; I <= m; I ++) {for (j = 0; j <step [a % 6]; j ++) h [sharp [a % 6] [j] [0] [I + sharp [a % 6] [j] [1]-1] ++; a/= 6 ;}for (I = 1; I <= m; I ++) {for (j = 0; j <step [B % 6]; j ++) h [sharp [B % 6] [j] [0]-tp] [I + sharp [B % 6] [j] [1]-1] ++; b/= 6 ;}for (I = 0; I <10; I ++) for (j = 0; j <10; j + +) If (h [I] [j]> 1) return false; return true;} int main () {freopen ("input.txt", "r", stdin ); freopen ("output.txt", "w", stdout); int r, I, j, x, ans, totol; while (~ Scanf ("% d", & n, & m) {Tol = 1; for (I = 1; I <= m; I ++) totol * = 6; num = 0; for (I = 0; I <totol; I ++) if (legal (I) canuse [++ num] = I; memset (dp, 0, sizeof (dp); memset (f, true, sizeof (f); for (I = 1; I <= num; I ++) for (j = 1; j <= num; j ++) for (x = 1; x <= 2; x ++) f [I] [j] [x] = OK (I, j, x); for (r = 1; r <= n; r ++) for (I = 1; I <= num; I ++) if (tall [I] + r <= n) for (j = 1; j <= num; j ++) if (f [I] [j] [1]) for (x = 1; x <= num; x ++) if (f [I] [x] [2]) dp [r] [j] [I] = max (dp [r] [j] [I], dp [r-1] [x] [j] + w [I]); ans = 0; for (I = 1; I <= num; I ++) ans = max (ans, dp [n] [I] [1]); printf ("% d,", ans) ;}return 0 ;}