There are several situations in which an n * m matrix is filled with 1*2 blocks.
Idea: Pressure dp, first pre-processing those States can reach each other, there are several situations, the last two 1, the next one also two 1, the last one is 0, the next must be 1, there is another case where the previous one is 1 and the next one is 0.
Then, let's go back and forth.
Code:
# Include
# Include
# Include using namespace std; int n, m, g [15555] [2], gn; long dp [2] [2111]; void dfs (int len, int now, int pre) {if (len> m) return; if (len = m) {g [gn] [0] = pre; g [gn ++] [1] = now; return;} dfs (len + 2, (now <2) | 3, (pre <2) | 3 ); dfs (len + 1, (now <1) | 1, pre <1); dfs (len + 1, now <1, (pre <1) | 1);} int main () {while (~ Scanf (% d, & n, & m) & n | m) {if (n <m) swap (n, m); gn = 0; dfs (0, 0, 0); printf (% d, gn); memset (dp, 0, sizeof (dp); dp [0] [(1 <