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 ...
随机推荐
- EFCore自动迁移
2019/05/14,EFCore 2.2.4 有两种方式: 使用Migrate()方法 if (DbContext.Database.GetPendingMigrations().Any()) { ...
- NMS(non maximum suppression,非极大值抑制)
"""nms输入的数据为box的左上角x1,y1与右下角x2,y2+confidence,rows=batch_size,line=[x1,y1,x2,y2,confid ...
- 【WEB基础】HTML & CSS 基础入门(1)初识
前面 我们每天都在浏览着网络上丰富多彩的页面,那么在网页中所呈现出的绚丽多彩的内容是怎么设计出来的呢?我们想要自己设计一个页面又该如何来做呢?对于刚刚接触网页设计的小伙伴来说,看到网页背后的一堆符号和 ...
- Activiti - eclipse安装Activiti Designer插件
下载链接:https://www.activiti.org/designer/archived/activiti-designer-5.18.0.zip 如果下载不了,翻墙吧! 参考: https:/ ...
- VS2017 密钥
需要的请自取- Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH
- Gitlab 重置 root 密码
要重置root密码,请先使用root权限登录服务器.使用以下命令启动Ruby on Rails控制台: gitlab-rails console production 等到控制台加载完毕,您可以通过搜 ...
- day 21 作业
定义MySQL类 对象有id.host.port三个属性 定义工具create_id,在实例化时为每个对象随机生成id,保证id唯一 提供两种实例化方式,方式一:用户传入host和port 方式二:从 ...
- Jenkins使用过程中注意事项
jenkins自动部署注意事项: 安装jenkins https://blog.csdn.net/qq_37372007/article/details/81586751 1.当提示错误ERROR: ...
- python测试开发django-44.xadmin上传图片和文件
前言 xadmin上传图片和上传文件功能 依赖环境 如果没安装Pillow的话,会有报错:practise.Upload.upload_image: (fields.E210) Cannot use ...
- 浅谈Python设计模式 - 单例模式
本篇主要介绍一下关于Python的单例模式,即让一个类对象有且只有一个实例化对象. 一.使用__new__方法(基类) 要实现单例模式,即为了让一个类只能实例化一个实例,那么我们可以去想:既然限制创建 ...