POJ 2411 Mondriaan\'s Dream

ad
Mondriaan's Dream
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 13211 Accepted: 7700

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. 
POJ 2411 Mondriaans Dream - NGUNAUJ - NGUNAUJ

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

POJ 2411 Mondriaans Dream - NGUNAUJ - NGUNAUJFor 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
先处理出每一行可能的状态。1表示竖着放 0表示横着放,出现的0必须是连续的偶数个。
状态转移方程:dp[i][a]=sum(dp[i-1][b])   b的状态中的1 表示竖着放的砖指向下一行。 状态a中的1指 数指 竖着放的砖指向上一行。
 
   
/* ***********************************************
Author :
Created Time :2015/8/2 13:27:48
File Name :1.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 2000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
int n,m;
int st[maxn];
int arr[11];
int top;
ll dp[11][1<<12];
void init(){
top=0;
int mark=0;
for(int i=0;i<(1<<m);i++){
cle(arr);
for(int j=0;j<m;j++){
if((i&(1<<j))==0){
arr[j]=1;
}
}
mark=0;
for(int k=0;k<m;k++){
if(arr[k]==1){
if(arr[++k]!=1){
mark=1;break;
}
}
}
if(!mark)
st[top++]=i;
}
}

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
//dp[i][x]=sum(dp[i-1][t]);
while(cin>>n>>m){
if(n==0&&m==0)break;
if(n>m)
swap(n,m);
cle(dp);
init();
for(int i=0;i<top;i++)
dp[0][st[i]]=1;
int sum=(1<<m);

for(int i=1;i<n;i++){
for(int x=0;x<top;x++){
for(int y=0;y<sum;y++){
if(dp[i-1][y]==0)continue;
if(((y)&(~st[x]))!=0)continue;
dp[i][st[x]-y]+=dp[i-1][y];
}
}
}
printf("%I64d\n",dp[n-1][0]);
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/u013077144/article/details/51212144