111c-Petya and spiders
At first, the board was filled with Spider. You can arrange each spider to walk in four adjacent directions, one second, and ask the maximum number of spaces after one second.
Practice: enumerate the movement direction of each column of spider. You can use state compression to determine the status of each row of spider after one second, it is worth judging whether each State can have three adjacent rows, namely, A, B, and C.
Only when (B | B> 1 | B <1 | A | C & (lim-1) = lim, B (> 1 <1 is not much like moving around) it can exist. What does not exist is that the upper layer of the first line has only 0. This status does not exist at the beginning.
/****** When we see such a small scale, we need to use State compression. Only two lines can be affected. Check whether the status exists. **********/# include <cstdio> # include <algorithm> # include <cstring> # define EPS -1e8using namespace STD; const int LMT = 1 <6; int DP [45] [LMT] [LMT], get [LMT], n, m, Lim; bool check (int, int B, int c) {int x = B | (B <1) | (B> 1) | A | C; Return (X & (lim-1 )) = (lim-1);} int work (int x) {int res, L; Res = L = 0; do if (X & 1) RES ++; while (x> = 1); Return M-res;} void Init (void) {for (INT I = 0; I <= n + 1; I ++) for (Int J = 0; j <LM T; j ++) for (int K = 0; k <LMT; k ++) DP [I] [J] [k] = EPS; for (INT I = 0; I <LMT; I ++) GET [I] = work (I); For (INT I = 0; I <Lim; I ++) DP [0] [0] [I] = 0;} int main (void) {int ans = 0; scanf ("% d", & N, & M); If (n <m) {int t = n; n = m; M = T;} Lim = 1 <m; Init (); for (INT I = 0; I <n; I ++) for (Int J = 0; j <Lim; j ++) for (int K = 0; k <Lim; k ++) if (DP [I] [J] [k]! = EPS) for (int l = 0; L <Lim; l ++) if (check (J, K, L )) DP [I + 1] [k] [l] = max (DP [I + 1] [k] [L], DP [I] [J] [k] + get [k]); For (Int J = 0; j <Lim; j ++) ans = max (ANS, DP [N] [J] [0]); printf ("% d \ n", ANS); Return 0 ;}
& Lim-1 failed