Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15407   Accepted: 8889

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 大意:h,w分别为一个矩形的长和宽(h,m<=11),问用1*2的小矩形(可横竖摆放),问一共有多少种方法。 状态压缩,竖着摆放的小矩形占据该行的该位置和上一行对应位置,0表示该位置不摆放(即下一行竖着摆放的小矩形占据这个位置),1表示该位置摆放(横或竖)
   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); 上一行对应位置无论如何被占据,当前行由下一行竖着摆放的矩形占据
dfs搜出所有可能的路径path[num][2];path[i][0]存第i条路的当前状态,path[i][1]存第i条路的上一行状态。
剩下的dp很常规。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define LL long long int path[][];
LL dp[][<<];
int h,w,num;
void dfs(int l,int now,int pre)
{
if(l>w)
return;
if(l==w)
{
path[num][]=now;
path[num++][]=pre;
return;
}
dfs(l+,now<<|,pre<<|);
dfs(l+,now<<|,pre<<);
dfs(l+,now<<,pre<<|);
} int main()
{
while(scanf("%d%d",&h,&w)!=EOF&&h+w)
{
num=;
dfs(,,);
memset(dp,,sizeof(dp));
dp[][(<<w)-]=;
for(int i=;i<h;i++)
for(int j=;j<num;j++)
dp[i+][path[j][]]+=dp[i][path[j][]];
printf("%I64d\n",dp[h][(<<w)-]);
}
return ;
}

POJ_2411_Mondriaan's Dream_状态压缩dp的更多相关文章

  1. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

  2. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  3. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  4. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  5. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  6. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  7. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  8. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  9. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

随机推荐

  1. Tensorflow人工智能入门(一)

    前言: 作为一个程序员,已经离开开发岗好多年,最近突然迷茫了,不知道自己何去何从.互联网技术发展的速度已快得难以想象,许久不码代码的手也越来越僵直,需求沟通中的套话和空话却越发的熟练,这和当年入行时的 ...

  2. 在全局对象(不是指针)的构造函数里不要对std集合做太多操作

    写MaxvisionOnvif的时候,我用个宏把每个Command类注册到了CommandBuilder里面,通过全局对象初始化实现的,如下: void CommandBuilder::Registe ...

  3. 文件描述符 VS 文件句柄

    文件描述符 VS 文件句柄 文件描述符是标准 C 里用的,是 int 型的,比如调用 open 函数成功后会返回一个与当前文件相关联的 int 型数字. 文件句柄是 Windows 里用的,是 HAN ...

  4. Spring cloud config配置文件加密解密

    Spring cloud config配置文件加密解密 学习了:http://blog.csdn.net/u010475041/article/details/78110349 学习了:<Spr ...

  5. 操作系统: 二级文件夹文件系统的实现(c/c++语言)

    操作系统的一个课程设计,实现一个二级文件夹文件系统. 用disk.txt模拟磁盘,使用Help查看支持的命令及其操作方式,root为超级用户(写在disk.txt中) 文件的逻辑结构:流式文件. 物理 ...

  6. 线段树 hdu3255 Farming

    做了这么多扫描线的题,,基本都是一个思路. 改来改去,,无非就是维护的节点的内容以及push_up越写越复杂了而已 首先将价格排序处理一下编号,变成编号越大的powerfol越大 然后后面加入扫描线的 ...

  7. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  8. SpringMVC中的 --- 异常处理

    系统异常处理器SimpleMappingExceptionResolver 处理器方法执行过程中,可能会发生异常,不想看到错误黄页,想看到一个友好的错误提示页. 自定义异常处理器 使用异常处理注解

  9. ext4文件系统制作 - make_ext4fs 参数介绍【转】

    本文转载自:http://blog.csdn.net/u011784994/article/details/53816976 make_ext4fs用于Android平台上制作ext4文件系统的镜像. ...

  10. Base Class Doesn't Contain Parameterless Constructor?

    http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor #regi ...