Question: Given a matrix, only 1X2 blocks can be placed, and how many different la s can be completely covered by this matrix.
Analysis: If the value is 11 and 01 is vertical, you only need to determine whether the State collection (j | k) of the two adjacent rows is full, whether the two statuses conflict (j & k ).
The first line is directly preprocessed.
# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace std; _ int64 dp [12] [1 <11]; // The value is 11 in the horizontal direction and 0 in the vertical direction. // 1 int buff [1 <11]; int n, m; _ int64 ans; bool judge (int B) {bool flag = 1; while (B) {if (B & 1) {if (B> 1) & 1) B = B> 2; else {flag = 0; B = B> 1 ;}} else B = B> 1; if (flag = 0) return 0 ;}return flag ;} void getbuff () {int total = 1 <11; for (int I = 0; I <total; I ++) {if (judge (I )) {buff [I] = 1 ;}}void solve () {int total = 1 <m; for (int I = 1; I <n; I ++) {// the last row must be 1 for (int j = 0; j <total; j ++) {for (int k = 0; k <total; k ++) {if (j | k) = total-1 & buff [(j & k)]) {dp [I] [j] + = dp [I-1] [k] ;}}}ans = dp [n-1] [total-1];} int main () {getbuff (); while (scanf ("% d", & n, & m) {if (n = 0 & m = 0) break; if (n = 1) {if (m % 2 = 0) printf ("1 \ n"); else printf ("0 \ n"); continue ;} int total = 1 <m; memset (dp, 0, sizeof (dp); for (int I = 0; I <total; I ++) {if (buff [I]) dp [0] [I] = 1;} ans = 0; solve (); printf ("% I64d \ n", ans );} return 0 ;}