The main idea: the I-type bricks with 2 * 1 on the grid of n *m Live 2 * 2 (missing a 1 *) L-type bricks, ask how many Zhong Pu methods
The idea of solving a problem: similar to POJ-2411 Mondriaan's dream
Here, S1 represents the state of the previous row, S2 represents the state of the current row, B1 indicates whether the previous column of the previous row has an effect on the current column, and B2 indicates whether the previous column of the current row has an effect on the current column
A table of state transitions can be obtained
The above excerpt from here to write the link content
#include <cstdio>#include <algorithm>#include <cstring>using namespace STD;#define N#define S (1 <<)Long LongAns[n][n], dp[n][s];intN, M;voidInit () {intTif(N < m) {t = n; n = m; m = t; }memset(DP,0,sizeof(DP)); dp[0][(1<< m)-1] =1;}voidDfsintRintCintS1,intS2,intB1,intB2) {if(c = = m) {if(!b1 &&!b2) {DP[R][S2] + = dp[r-1][S1]; }return; }if(!b1 &&!b2) {DFS (R, C +1, S1 <<1, (S2 <<1) |1,0,0); DFS (R, C +1, S1 <<1, (S2 <<1) |1,1,0); DFS (R, C +1, S1 <<1, (S2 <<1) |1,0,1); }if(!B1) DFS (R, C +1, S1 <<1, (S2 <<1) | B2,1,1);if(!B2) {DFS (R, C +1, (S1 <<1) | (1-B1), (S2 <<1) |1,0,1); DFS (R, C +1, (S1 <<1) | (1-B1), (S2 <<1) |1,1,1); } DFS (r, C +1, (S1 <<1) | (1-B1), (S2 <<1) | B2,0,0);}voidSolve () { for(inti =1; I <= N; i++) DFS (i,0,0,0,0,0);printf("%lld\n", ans[n][m] = ans[m][n] = dp[n][(1<< m)-1]);}intMain () {memset(ANS,-1,sizeof(ans)); while(scanf("%d%d", &n, &m)! = EOF) {if(Ans[n][m]! =-1) {printf("%lld\n", Ans[n][m]);Continue; } init (); Solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SGU-131 Hardwood Floor (state compression)