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. PKI 的组成

    PKI(Public Key Infrastructure)公钥基础设施是提供公钥加密和数字签名服务的系统或平台,目的是为了管理密钥和证书.一个机构通过采用PKI 框架管理密钥和证书可以建立一个安全的 ...

  2. asp.net--mvc--异步编程

    Using Asynchronous Methods in ASP.NET MVC 4 asp.net mvc中的异步只能增加系统的性能,原来需要500个线程的,现在需要50个就够了,对一些常规的程序 ...

  3. [bzoj2783][JLOI2012]树_树的遍历

    树 bzoj2783 JLOI2012 题目大意:给定一棵n个点的树.求满足条件的路径条数.说一个路径是满足条件的,当且仅当这条路径上每个节点深度依次递增且点权和为S. 注释:$1\le n\le 1 ...

  4. spring boot.定时任务问题记录(TaskScheduler/ScheduledExecutorService异常)

    一.背景 spring boot的定时任务非常简单,只需要在启动类中加上@EnableScheduling注解,然后在对应的方法上配置@Scheduled就可以了,系统会自动处理并按照Schedule ...

  5. 使用JConsole观察分析Java程序的运行(转)

    一.JConsole是什么 从Java 5开始 引入了JConsole.JConsole是一个内置Java性能分析器,可以从命令行或在GUI shell中运行.您可以轻松地使用JConsole(或者, ...

  6. asciiflow

    http://asciiflow.com/ https://maxiang.io/# http://www.jianshu.com/p/19432b5e3c60

  7. PHP array_fill()

    定义和用法 array_fill() 函数用给定的值填充数组,返回的数组有 number 个元素,值为 value.返回的数组使用数字索引,从 start 位置开始并递增.如果 number 为 0 ...

  8. HDOJ题目3440 House Man(差分约束)

    House Man Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. Lucene5学习之使用MMSeg4j分词器

      分类:程序语言|标签:C|日期: 2015-05-01 02:00:24 MMSeg4j是一款中文分词器,详细介绍如下: 1.mmseg4j 用 Chih-Hao Tsai 的 MMSeg 算法( ...

  10. 升级到VS2013常见问题

    问题1: Building an MFC project for a non-Unicode character set is deprecated 解决方法: 用于多字节字符编码 (MBCS) 的 ...