[poj2411] Mondriaan's Dream (状压DP)
状压DP
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
题目大意
给出一个n * m 的矩形,让你用1 * 2 的矩形去填满,问有多少种方案
题解
由于题目给出的数据很小,所以可以直接状压,枚举每一行的状态向后转移。
代码
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
long long dp[13][1 << 11];
long long temp;
int n,m;
void dfs(int i,int p,int k) {
if (k >= m) {
dp[i][p] += temp;return;
}
dfs(i,p,k + 1);
if (k <= m - 2 && !(p&(1 << (k + 1))) && !(p&(1 << (k)))) {
dfs(i,p | 1 << (k + 1) | 1 << k,k + 2);
}
}
int main() {
while (cin >> n >> m && n && m) {
memset(dp,0,sizeof(dp));
temp = 1;
int ed = 1 << m;
dfs(0,0,0);
for (int i = 1; i < n; i++)
for (int j = 0; j < ed; j++)
if (dp[i - 1][j]) {
temp = dp[i - 1][j];
dfs(i,~j&((1 << m) - 1),0);
}
cout << dp[n-1][ed-1] << endl;
}
return 0;
}
[poj2411] 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)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- POJ 2411 Mondriaan's Dream ——状压DP 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- $POJ2411\ Mondriaan's\ Dream$ 状压+轮廓线$dp$
传送门 Sol 首先状压大概是很容易想到的 一般的做法大概就是枚举每种状态然后判断转移 但是这里其实可以轮廓线dp 也就是从上到下,从左到右地放方块 假设我们现在已经放到了$(i,j)$这个位置 那么 ...
- POJ-2411 Mondriann's Dream (状压DP)
求把\(N*M(1\le N,M \le 11)\) 的棋盘分割成若干个\(1\times 2\) 的长方形,有多少种方案.例如当 \(N=2,M=4\)时,共有5种方案.当\(N=2,M=3\)时, ...
- poj2411 Mondriaan's Dream (轮廓线dp、状压dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17203 Accepted: 991 ...
- POJ 2411 Mondriaan'sDream(状压DP)
题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...
- POJ2411 - Mondriaan's Dream(状态压缩DP)
题目大意 给定一个N*M大小的地板,要求你用1*2大小的砖块把地板铺满,问你有多少种方案? 题解 刚开始时看的是挑战程序设计竞赛上的关于铺砖块问题的讲解,研究一两天楞是没明白它代码是怎么写的,智商捉急 ...
- POJ2411 Mondriaan's Dream 题解 轮廓线DP
题目链接:http://poj.org/problem?id=2411 题目大意 给你一个 \(n \times m (1 \le n,m \le 11)\) 的矩阵,你需要用若干 \(1 \time ...
随机推荐
- imx6 关闭调试串口
需要关闭imx6调试串口,用作普通的串口使用. 参考链接 http://blog.csdn.net/neiloid/article/details/7585876 http://www.cnblogs ...
- LeetCode House Robber III
原题链接在这里:https://leetcode.com/problems/house-robber-iii/ 题目: The thief has found himself a new place ...
- 继续Django
环境准备 1. 创建一个Django后,Django的目录: │ manage.py │ ├─Django_s1 │ settings.py │ urls.py │ wsgi.py │ __in ...
- Java jdbc 连接oracle之二(使用properties文件)
driver = oracle.jdbc.driver.OracleDriver url = jdbc:oracle:thin:@192.168.10.105:1521:orcl user = LF ...
- Linux中可用于管道操作的命令总结
在Linux中药进行稍复杂的操作,通常需要借助管道命令"|"多个命令的组合,形式如下: command 1 | command 2 | command 3 -- 在linux中 ...
- Hdu 1081 To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- paper 129 : 比较好的开源人脸识别软件
1.face.com 以色列公司,某年六月时被Facebook收购,同时暂停了API服务,之前测试过他们的服务,基本上是了解到的应用中做得最牛的了. 2.orbe Orbeus由麻省理工学院和波士顿大 ...
- Bug修正
名称:nice! 项目名称:约跑app 组长:李权 成员:韩媛媛 刘芳芳 宫丽君 于淼 Bug修正: 1.我看到的现象:退出当前的账号后,按返回键可以再次进入登录界面. 期待的现象:能够安全登陆和退出 ...
- 该字符串未被识别为有效的 DateTime
开发语言C#,System.Data.SQLite.dll驱动. SQLserver数据库转换为SQLite数据库时,日期类型默认转为DATETIME. 执行查询SQL语句,数据为空(查询不到数据时) ...
- oracle中scn(系统改变号)
系统scn: select checkpoint_change# from v$database; 文件scn: select name ...