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 ...
随机推荐
- Java之路---Day06
2019-10-20-23:13:52 目录内容: 1.Scanner类 2.匿名对象 3.Random类 4.对象数组 Scanner类 功能:实现键盘输入数据到程序中 使用步骤: 1.导包: im ...
- Oracle数据库之操作符及函数
一.操作符: 1.分类: 算术.比较.逻辑.集合.连接: 2.算术操作符: 执行数值计算: -- 工资加1000 from emp; 3.比较操作符: -- 比较运算符(between and包头不包 ...
- slf4j的正确使用
头两天领导分配个任务是要把项目中所有try catch里的异常处理收集到elk中,由于之前的处理方式五花八门,就集中处理了下, 事后还被批评了. 不是所有的异常信息都需要被记录到log中 使用SLF4 ...
- Android Studio 打包生成apk
打开AndroidStudio,并且打开想要生成apk文件的项目 点击工具栏上面的“Builder” 点击“Builder”之后在下拉菜单里面可以看到“Genarate Singed APK”,点 ...
- 【RAC】将RAC备份集恢复为单实例数据库
[RAC]将RAC备份集恢复为单实例数据库 一.1 BLOG文档结构图 一.2 前言部分 一.2.1 导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识, ...
- Docker的系统资源限制及验正
Docker的系统资源限制及验正 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.容器资源限制概述 1>.什么是"Limit a container's reso ...
- Java 返回字符串中第一个不重复字符的下标 下标从0开始
比如abcdefgabdef 其中字符c和g不重复,返回c的小标,下标从0开始,那么是2 package com.example.demo; import org.testng.annotations ...
- python deque的内在实现 本质上就是双向链表所以用于stack、队列非常方便
How collections.deque works? Cosven 前言:在 Python 生态中,我们经常使用 collections.deque 来实现栈.队列这些只需要进行头尾操作的 ...
- 2018年第十届ACMICPC四川省大学程序设计竞赛
..拿金了 没给学校丢脸 A ....SB题啊 比赛的时候都没看 裸的一个bitset前缀和 先开一个1e4*1e4的二维bitset数组 初始第i个数组的值为1 << i (即B[i]= ...
- 摘:J2EE开发环境搭建(1)——安装JDK、Tomcat、Eclipse
J2EE开发环境搭建(1)——安装JDK.Tomcat.Eclipse 1:背景 进公司用SSH(Struts,spring和hibernate)开发已经有两个月了,但由于一 直要么只负责表示层的开发 ...