首页 > 代码库 > poj2411
poj2411
Mondriaan‘s Dream
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 12111 | Accepted: 7058 |
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!
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 21 31 42 22 32 42 114 110 0
Sample Output
10123514451205
Source
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<set>using namespace std;#define LL long longLL dp[12][1<<11+1];int path[140000][2],h,w,temp,tann;void dfs(int l,int now,int pre){ if(l>w) return ; if(l==w) { path[tann][0]=now; path[tann++][1]=pre; return ; } dfs(l+2,(now<<2)|3,(pre<<2)|3); dfs(l+1,(now<<1)|1,pre<<1); dfs(l+1,now<<1,(pre<<1)|1);}int main(){ while(scanf("%d%d",&h,&w)!=EOF) { tann=0; memset(dp,0,sizeof(dp)); memset(path,0,sizeof(path)); if(h==0&&w==0) { break; } if(w>h) { temp=w; w=h; h=temp; } dfs(0,0,0); dp[0][(1<<w)-1]=1; for(int i=0;i<h;i++) for(int j=0;j<tann;j++) dp[i+1][path[j][0]]+=dp[i][path[j][1]]; printf("%lld\n",dp[h][(1<<w)-1]); } return 0;}
poj2411
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。