Mondriaan’s Dream

Time Limit: 3000MS Memory Limit: 65536K

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

Source

Ulm Local 2000

题意:用1*2的砖块来覆盖地面的方案数.

/*
状压DP.
f[i][S]表示当前第i行,状态为S.
我们发现每一行状态只和前一行相关.
然后就可以DP辣.
枚举所有可行状态转移.
0 不放/竖着的上面那块
1 横着/竖着的下面那块
强行把竖着的状态给下边那个.
因为必须要填满,
所以状态合不合法就比较好转移了.
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 5001
#define LL long long
using namespace std;
LL f[21][MAXN];
int n,m;
bool pre(int s)
{
for(int i=0;i<m;)
{
if(s&(1<<i))
{
if(i==m-1) return false;
if(s&(1<<i+1)) i+=2;
else return false;
}
else i++;
}
return true;
}
bool check(int s,int ss)
{
for(int i=0;i<m;)
{
if(s&(1<<i))
{
if(ss&(1<<i))
{
if(i==m-1||!(s&(1<<i+1))||!(ss&(1<<i+1))) return false;
else i+=2;
}
else i++;
}
else {
if(!(ss&(1<<i))) return false;
else i++;
}
}
return true;
}
void slove()
{
memset(f,0,sizeof f);
for(int s=0;s<=(1<<m)-1;s++) if(pre(s)) f[1][s]=1;
for(int i=2;i<=n;i++)
for(int s=0;s<=(1<<m)-1;s++)
for(int ss=0;ss<=(1<<m)-1;ss++)
if(check(s,ss)) f[i][s]+=f[i-1][ss];
printf("%lld\n",f[n][(1<<m)-1]);
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(!n&&!m) break;
if(n<m) swap(n,m);
slove();
}
return 0;
}

Poj 2411 Mondriaan's Dream(状压DP)的更多相关文章

  1. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  2. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  3. POJ 2411 Mondriaan'sDream(状压DP)

    题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...

  4. [poj2411] Mondriaan's Dream (状压DP)

    状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...

  5. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

  6. POJ - 2411 Mondriaan's Dream(轮廓线dp)

    Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...

  7. poj 2411 Mondriaan's Dream(状态压缩dP)

    题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...

  8. poj 2411 Mondriaan's Dream (轮廓线DP)

    题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...

  9. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

随机推荐

  1. 新安装jenkins要记录的点。

    突然很早之前部署的jenkins 由于版本低存在漏洞,被人搞了,在docker中新安装jenkins出现了各种问题,避免跳坑. 不能正确安装插件, Jenkins -> Plugin Manag ...

  2. ELK学习笔记之使用curl命令操作elasticsearch

    0x00 _cat系列 _cat系列提供了一系列查询elasticsearch集群状态的接口.你可以通过执行curl -XGET localhost:9200/_cat 1. 获取所有_cat系列的操 ...

  3. Spring AOP 创建Advice 定义pointcut、advisor

    前面定义的advice都是直接植入到代理接口的执行之前和之后,或者在异常发生时,事实上,还可以对植入的时机定义的更细. Pointcut定义了advice的应用时机,在Spring中pointcutA ...

  4. java之spring之依赖注入

    一.DI: Dependency injection; 依赖注入 依赖注入和控制反转是同一个概念的不同说法. 对象的创建依赖于容器.对象属性的设置是由容器来设置. 对象属性的赋值过程称为注入. 二.S ...

  5. java之spring之对象的创建

    首先提供目录结构如下: 下面提供各文件代码,以供参考: UserDynamicFactory.java package cn.sxt.factory; import cn.sxt.vo.User; / ...

  6. copy file

    import io,,,,,,, from https://pub.dev/packages/large_file_copy Directory directory = await getApplic ...

  7. Oracle 逻辑存储结构

    一.总述 逻辑存储结构是 Oracle 数据库存储结构的核心内容,对 Oracle 数据库的所有操作都会涉及逻辑存储结构.逻辑存储结构是从逻辑的角度分析数据库的组成,是对数据存储结构在逻辑概念上的划分 ...

  8. spring 中的 bean 是线程安全的吗?

    spring 中的 bean 是线程安全的吗? Spring 不保证 bean 的线程安全. 默认 spring 容器中的 bean 是单例的.当单例中存在竞态条件,即有线程安全问题.如下面的例子 计 ...

  9. ifup/ifdown

    这两个程序其实是script而已,它会直接到 /etc/ sysconfig/network-scripts目录下搜索对应的配置文件,例如ifup eth0,它会找出ifcfg-eth0这个文件的内容 ...

  10. MongoDB 目录分析、基础命令、参数设置

    目录分析 1.整体目录 以msi默认的data.log路径安装,才会有data.log文件夹. 2.bin目录 3.log目录 基础命令 1.服务器端基础命令 net  start  MongoDB  ...