poj2411Mondriaan's Dream
2014-09-06 19:47
417 查看
Mondriaan's Dream
DescriptionSquares 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 dreamtof 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!InputThe 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.OutputFor 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 symmetricaltilings multiple times.Sample Input
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 11810 | Accepted: 6866 |
1 2 1 3 1 4 2 2 2 3 2 4 2 11 4 11 0 0Sample Output
1 0 1 2 3 5 144 51205
题意:给你n*m的地板,1*2的地板砖,问将地板铺满的方案数
解题思路:刚刚接触轮廓线dp,这题是比较经典的,1*2的地板砖可以横放,竖放,还可以不放,我们只需分三种情况讨论他的轮廓线状态,详细分析参见大白书。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longLL dp[2][1<<11];int m;void update(int t,int a,int b){if(b&(1<<m))dp[t][b^(1<<m)]+=dp[1-t][a];}int main(){int n;while(scanf("%d%d",&n,&m)!=EOF){if(n==0&&m==0)break;int t=0;memset(dp,0,sizeof(dp));dp[0][(1<<m)-1]=1;for(int i=0;i<n;i++){for(int j=0;j<m;j++){t=1-t;memset(dp[t],0,sizeof(dp[t]));for(int k=0;k<(1<<m);k++){if(!dp[1-t][k])continue;//bufangupdate(t,k,k<<1);//shufangif(i&&!((1<<m-1)&k))update(t,k,(k<<1)^1^(1<<m));//hengfangif(j&&!(k&1))update(t,k,(k<<1)^3);}}}printf("%lld\n",dp[t][(1<<m)-1]);}return 0;}
相关文章推荐
- [BZOJ1226][SDOI2009][状态压缩DP]学校食堂Dining
- bzoj3312 [Usaco2013 Nov]No Change
- POJ 3311 Hie with the Pie (状压DP)
- 动态规划晋级——POJ 3254 Corn Fields【状压DP】
- 状态压缩DP 之 poj 2686
- poj 2411
- 炮兵阵地
- Corn Fields
- Hie with the Pie
- Bottle Taps
- codeforces 377C Captains Mode
- poj 1185 炮兵阵地
- HDU1074Doing Homework 状态压缩DP入门
- HDU4336 Card Collector
- POJ 3254 Corn Fields 状态压缩dp
- zoj-3777-Problem Arrangement(状态压缩DP)
- HDU 1074 Doing Homework 状态压缩DP
- HDU 1565 方格取数(1) 状态压缩DP
- POJ 1185 炮兵阵地
- POJ 2411 Mondriaan's Dream