poj 2411 Mondriaan's Dream 骨牌铺放 状压dp
题目链接
题意
用\(1\times 2\)的骨牌铺满\(H\times W(H,W\leq 11)\)的网格,问方案数。
思路
参考focus_best.
竖着的骨牌用\(\begin{pmatrix}0\\1\end{pmatrix}\)表示,横着的骨牌用\(\begin{pmatrix}1&1\end{pmatrix}\)表示。
则对于第\(i\)行,与之相容的第\(i-1\)行的状态需满足:
- 第\(i\)行是0的位置,第\(i-1\)行必须是1;
- 第\(i\)行是1的位置,第\(i-1\)行可为1可为0;如果是1则需满足,这样的连续的1的个数必为偶数(因为为横放)。
此外,
最后一行必为全1状态,
第一行需满足可以作为第一行的条件:这等价于,第一行的上一行可以表示为全1状态。
Code
#include <cstdio>
#include <cstring>
#include <iostream>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
#define maxn 13
#define maxs 2100
using namespace std;
typedef long long LL;
int h, w; LL dp[maxs][maxn];
bool vis[maxs][maxn], hori[maxn];
bool check(int s1, int s2) {
memset(hori, 0, sizeof hori);
F(i, 0, w) {
if (!(s2&(1<<i))) {
if (!(s1&(1<<i))) return false;
}
else {
if (s1&(1<<i)) hori[i] = true;
}
}
int cont = 0; bool flag = false;
F(i, 0, w+1) {
if (!hori[i]) {
if (cont&1) return false;
cont = 0;
}
else ++cont;
}
return true;
}
LL dfs(int state, int row) {
if (!row) {
if (state==(1<<w)-1) return 1;
else return 0;
}
if (vis[state][row]) return dp[state][row];
vis[state][row] = true;
LL temp=0;
F(i, 0, 1<<w) {
if (check(i, state)) temp += dfs(i, row-1);
}
return dp[state][row] = temp;
}
void work() {
memset(vis, 0, sizeof vis);
memset(dp, 0, sizeof dp);
if (h<w) swap(h,w);
printf("%lld\n", dfs((1<<w)-1, h));
}
int main() {
while (scanf("%d%d", &h, &w) != EOF && h && w) work();
return 0;
}
poj 2411 Mondriaan's Dream 骨牌铺放 状压dp的更多相关文章
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- 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's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- [POJ] 2411 Mondriaan's Dream
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- 多米诺骨牌放置问题(状压DP)
例题: 最近小A遇到了一个很有趣的问题: 现在有一个\(n\times m\)规格的桌面,我们希望用\(1 \times 2\)规格的多米诺骨牌将其覆盖. 例如,对于一个\(10 \times 11\ ...
- POJ 1038 Bugs Integrated Inc (复杂的状压DP)
$ POJ~1038~~\times Bugs~Integrated~Inc: $ (复杂的状压DP) $ solution: $ 很纠结的一道题目,写了大半天,就想练练手,结果这手生的.其实根据之前 ...
- 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 ...
随机推荐
- 【bug】【yii】配置log时,报错 Setting read-only property: yii\web\Application::log
Setting read-only property: yii\web\Application::log 配置放在了 components 外面,应该放在里面
- JZOJ 4743. 积木
Description Input Output Sample Input 38 7 63 9 41 10 5 Sample Output 18
- 权限组件(12):自动发现项目中有别名的URL
自动发现项目中所有有别名的URL,效果如下: customer_list {'name': 'customer_list', 'url': '/customer/list/'} customer_ad ...
- 662. Maximum Width of Binary Tree
https://leetcode.com/problems/maximum-width-of-binary-tree/description/ /** * Definition for a binar ...
- A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...
- [GDOI2016][树链剖分+主席树]疯狂动物城
题面 Description Nick 是只在动物城以坑蒙拐骗为生的狐狸,儿时受到偏见的伤害,放弃了自己的理想.他被兔子 Judy 设下圈套,被迫与她合作查案,而卷入意想不到的阴谋,历尽艰险后成为搭档 ...
- Java并发模型框架
构建Java并发模型框架 Java的多线程特性为构建高性能的应用提供了极大的方便,但是也带来了不少的麻烦.线程间同步.数据一致性等烦琐的问题需要细心的考虑,一不小心就会出现一些微妙的,难以调试的错误. ...
- 在F12 控制台输入,可执行jquery操作
<!-- 控制台执行jquery -->var importJs=document.createElement('script') //在页面新建一个script标签importJs.se ...
- Redis实现之对象(四)
类型检查与命令多态 Redis中用于操作键的命令基本上可以分为两种类型:其中一种命令可以对任何类型的键执行,比如DEL命令.EXPIRE命令.RENAME命令.TYPE命令.OBJECT命令等.举个栗 ...
- datagrid的修改和删除功能的实现
1.修改 双击,进入一行的编辑状态的功能的实现 2.删除 3.扩展easyui的datagrid,添加动态增加或删除Editor的方法 (1)背景要求: 对于某一列,比如密码,动态增加时候,是可以编辑 ...