Problem Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.
Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Input
The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.
Output
For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.
Sample Input
1 2 1 3 1 4 2 2 2 3 2 4 2 11 4 11 0 0
Sample Output
1 0 1 2 3 5 144 51205
*********************************************************************************************
Compressed binary state, and finally get this problem figured out! ! Brief explanation of code
*********************************************************************************************
1 / * 2 compressed state, binary, . 3 0 indicates forward upright, then the next row must be 1, . 4 1 represents placed horizontally, does not interfere with the next line . 5 * / . 6 #include <the iostream> . 7 #include < String > . 8 #include <CString> . 9 #include <the cmath> 10 #include <cstdio> . 11 #include <algorithm> 12 is the using namespace STD; 13 is Long W, H, I; 14 Long Long DP [ 15 ] [( . 1 < < 13 is )]; 15 BOOL Qihe ( LongX) // determined legal status 16 { . 17 for ( Long I = 0 ; I < W;) 18 is IF ((X & ( . 1 << I))> 0 ) . 19 { 20 is IF ((I == w to . 1 ) || ((X & ( . 1 << (I + . 1 ))) == 0 )) 21 is return to false ; 22 is I = + 2 ; 23 is } 24 the else I ++ ; 25 return to true ; 26 is } 27 BOOL Tran ( int a, int b) // row a state transformation to the b-state of the next line on the determining whether to meet the 28 { 29 for ( int I = 0 ; I < W;) 30 { 31 is IF ((a & ( . 1 << I))> 0 ) 32 { 33 is IF ((B & ( . 1 << I)) == 0 ) I ++ ; 34 is the else IF (I == w to . 1 || (A & ( . 1 << (I + . 1 ))) == 0 || (B & ( . 1<<(i+1)))==0)return 0; 35 else i+=2; 36 } 37 else if((b&(1<<i))>0)i++; 38 else return 0; 39 } 40 return 1; 41 } 42 int main() 43 { 44 while(cin>>h>>w) 45 { 46 if(h==0&&w==0) 47 break; 48 memset(dp,0,sizeof(dp)); 49 if(w==0||h==0) 50 { 51 printf("0\n"); 52 continue; 53 } 54 if(w>h) 55 { 56 int tmp; 57 tmp=w; 58 w=h; 59 h=tmp; 60 } 61 is int Z = . 1 << W; 62 is for (I = 0 ; I <Z; I ++) // first processing line separately out 63 is IF (Qihe (I)) 64 DP [ . 1 ] [I ] = . 1 ; 65 for (I = 2 ; I <= H; I ++ ) 66 { 67 for ( Long J = 0 ; J <Z; J ++ ) 68 { 69 DP [I] [J] = 0 ; 70 for (Long K = 0 ; K <Z; K ++ ) 71 is IF (Tran (K, J)) // state conversion 72 DP [I] [J] + DP = [I- . 1 ] [K]; 73 is } 74 } 75 << DP COUT [H] [Z- . 1 ] << endl; // output 76 } 77 return 0 ; 78 79 }
adhere to! ! ! ! victory! ! ! !
Reproduced in: https: //www.cnblogs.com/sdau--codeants/p/3311713.html