Poj 2411 Mondriaan's Dream(状压DP)
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)的更多相关文章
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- POJ 2411 Mondriaan's Dream ——状压DP 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- POJ 2411 Mondriaan'sDream(状压DP)
题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...
- [poj2411] Mondriaan's Dream (状压DP)
状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...
- POJ - 2411 Mondriaan's Dream(轮廓线dp)
Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- poj 2411 Mondriaan's Dream (轮廓线DP)
题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
随机推荐
- UOJ424 Count 生成函数、多项式求逆、矩阵快速幂
传送门 两个序列相同当且仅当它们的笛卡尔树相同,于是变成笛卡尔树计数. 然后注意到每一个点的权值一定会比其左儿子的权值大,所以笛卡尔树上还不能够存在一条从根到某个节点的路径满足向左走的次数\(> ...
- Robot Arms AtCoder - 4432 (构造)
大意: 给定平面上$n$个点$(x_i,y_i)$. 要求构造一个序列$d$, $d_i$表示每步走的距离, 再构造$n$个命令串, 要求从原点出发按照第$i$个命令走, 走完恰好到达$(x_i,y_ ...
- 解决C#调用COM组件异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT)的错误
最近C#调用COM时,遇到了异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT)的错误 后面找了一下,发现是在线程里调用COM组件引起的. C++调用COM时,会调用 ...
- SSM前后端分离 ssm+html+js(ajax) 这种controll层的返回值是结合或者网址
提示: 1.单表查询多条数据用 list<实体类名字> mapper层 1.1单表查询单条数据用 对象 2.两表关联查多条 list<map<String,Object> ...
- Maven打包时集成依赖项或复制依赖项到指定目录
1.集成依赖项,最后生成的jar文件包含所有依赖: <build> <plugins> <plugin> <artifactId>maven-assem ...
- Html-CSS-细节处理
1.input 添加padding后宽度会变化 input中添加如下样式,固定 box 的尺寸 box-sizing: border-box; -webkit-box-sizing: border-b ...
- Flask入门很轻松 (一)
转载请在文章开头附上原文链接地址:https://www.cnblogs.com/Sunzz/p/10956837.html Flask诞生于2010年,是Armin ronacher(人名)用 Py ...
- MySQL-CentOS7上安装Mysql5.7
#安装 wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm .noarch.rpm yum instal ...
- 构建nodejs环境
总想留下点东西,不负年华! 00.download releasehttps://nodejs.org/dist/ //all release example https://nodejs. ...
- nodejs 删除空文件
var fs = require("fs") var path = require("path") var listRealPath = path.resolv ...