Mondriaan ' s Dream
Time limit:3000ms Memory limit:65536k
Total submissions:16284 accepted:9420
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 O F His paper is 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 is in this material, he saw at a glance so he ' ll need a computer to calculate the number of ways to fill t He large rectangle whose dimensions were integer values, as well. Help him, so that he dream won ' t turn into a nightmare!
Input
The input contains several test cases. Each test case was made up of the 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 is 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
Analysis
Test instructions: Give a n*m grid, fill with 1*2 dominoes, ask for several filling methods
Compared to poj3133, the problem is simply ...
Make contour line DP when the screen of the illegal state is OK, specific look at the note clam.
Code
POJ 2411 Mondriaan's Dream #include <iostream> #include <cstring> #include <cstdio> #define FO (i,j,k)
for (i=j;i<=k;i++) using namespace std;
int n,m,p,q;
Long Long dp[2][1<<15];
int main () {int i,j,k,now;
while (scanf ("%d%d", &n,&m) && n && m) {memset (dp,0,sizeof DP);
now=0;
if (m>n) swap (n,m);
dp[0][(1<<m) -1]=1;
Fo (i,0,n-1) fo (j,0,m-1) {now^=1;
memset (dp[now],0,sizeof Dp[now]); Fo (k,0, (1<<m)-1) {//1. If A[I][J] is not put, then a[i-1][j] must be 1 if (k& (1<
; <m-1)) dp[now][(k<<1) & ((1<<m)-1)]+=dp[now^1][k]; 2. If you put a slender block, then a[i-1][j] must be 0 if (i &&!
k& (1<<m-1)) dp[now][((k<<1) & ((1<<m)-1)) |1]+=dp[now^1][k]; 3. If you put a lie-down block, then a[i][j-1] must be 0, and A[i-1][j]=1 if (J &&!) ( k&1) && (k& (1<<m-1)) dp[now][((k<<1) & ((1<<m)-1)) |3]+=dp[now^1][
K];
}} printf ("%lld\n", dp[now][(1<<m)-1]);
} return 0; }