题目链接

题意

用\(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\)行的状态需满足:

  1. 第\(i\)行是0的位置,第\(i-1\)行必须是1;
  2. 第\(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的更多相关文章

  1. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  2. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  3. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  4. Poj 2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...

  5. [POJ] 2411 Mondriaan's Dream

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...

  6. 多米诺骨牌放置问题(状压DP)

    例题: 最近小A遇到了一个很有趣的问题: 现在有一个\(n\times m\)规格的桌面,我们希望用\(1 \times 2\)规格的多米诺骨牌将其覆盖. 例如,对于一个\(10 \times 11\ ...

  7. POJ 1038 Bugs Integrated Inc (复杂的状压DP)

    $ POJ~1038~~\times Bugs~Integrated~Inc: $ (复杂的状压DP) $ solution: $ 很纠结的一道题目,写了大半天,就想练练手,结果这手生的.其实根据之前 ...

  8. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

  9. POJ - 2411 Mondriaan's Dream(轮廓线dp)

    Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...

随机推荐

  1. 1- vue django restful framework 打造生鲜超市

    Vue+Django REST framework实战 使用Python3.6与Django2.0.2(Django-rest-framework)以及前端vue开发的前后端分离的商城网站 项目支持支 ...

  2. JZOJ 5842

    Description 给定一个n*m 的 01 矩阵,求包含[l,r]个 1 的子矩形个数. Input 第一行,两个正整数n,m.接下来n 行,每行一个长度为 m 的 01 串,表示给定的矩阵.接 ...

  3. Thinkphp5中的Validate验证器的使用

    更多笔记: http://note.youdao.com/noteshare?id=e97a5df64888f27d912b3e966b9ec297&sub=web1520841813815 ...

  4. python * args和** kwargs的用法

    所属网站分类: python基础 > 函数 作者:慧雅 链接: http://www.pythonheidong.com/blog/article/18/ 来源:python黑洞网 www.py ...

  5. 初识java,编写hello world语句

    JDK: Java Develpment Kit - java开发工具包 JRE: Java Runtime Environment - java运行环境 JVM: Java Virtual Mach ...

  6. Spring---环境搭建与包介绍

    jar包下载路径 首先需要下载Spring框架 spring-framework-5.0.0.RELEASE-dist,官方地址为https://repo.spring.io/release/org/ ...

  7. Android 自定义debug.keystore

    场景分析: 有时候,我们要使用第三方的服务,需要提供自己的包名以及keystore的sha1值,比如微信支付,百度地图,都需要包名和keystore的sha1值作为唯一标识.这时候我们测试的时候,如果 ...

  8. va_list

    void Log( const TCHAR *pszFormat, ... ) { TCHAR buf[] ; va_list arglist ; try { _tcscpy_s ( buf, , _ ...

  9. 【Pow(x,n)】

    题目: Implement pow(x, n). 代码: class Solution { public: double myPow(double x, int n) { double ret = S ...

  10. Linux之ubuntu系统操作学习笔记

    1,swp分区:当内存不够时用swp分区顶替内存 2,语言环境检查  locale –a:可以明白系统支持什么语言 3,安装软件: apt-cache search(软件):搜索软件 apt-cach ...