题目链接

题意

用\(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. 精读《Epitath 源码 - renderProps 新用法》

    1 引言 很高兴这一期的话题是由 epitath 的作者 grsabreu 提供的. 前端发展了 20 多年,随着发展中国家越来越多的互联网从业者涌入,现在前端知识玲琅满足,概念.库也越来越多.虽然内 ...

  2. 微信在浏览器打开前的提示页面Android与IOS判断

    直接在网上扒一个页面,分分钟搞定!  先看一下效果 这是用微信开发工具打开的样式,直接上完整代码 <!DOCTYPE html> <html lang="en"& ...

  3. linux下mysql的权限设计总结

    1,进入mysql,终端中输入 mysql -u 用户名 -p   .enter键后,提示输入密码. 2,执行grant all privileges on xxxdb.* to usertest@& ...

  4. Ecshop里添加多个h1标题

    目录 功能: 思路: 效果: pageheader_list.htm里 product_sn_list.htm模板里 控制器里 功能: 点击页面右边的两个按钮,切换下面的<div class=& ...

  5. 精通SpringBoot--整合Redis实现缓存

    今天我们来讲讲怎么在spring boot 中整合redis 实现对数据库查询结果的缓存.首先第一步要做的就是在pom.xml文件添加spring-boot-starter-data-redis.要整 ...

  6. (WPF&Silverlight)silverlight自定义控件

    2个半小时弄懂了自定义控件是怎么回事儿. 在silverlight中创建一个UserControl,把上面sliderbar的外观和功能都封装在里面. 以自定义控件mapslider控件为例: 1.首 ...

  7. hadoop: Shuffle过程详解 (转载)

    原文地址:http://langyu.iteye.com/blog/992916 另一篇博文:http://www.cnblogs.com/gwgyk/p/3997849.html Shuffle过程 ...

  8. Java面向对象---类与对象的关系

    类是对某一类事物的描述,是抽象的.概念上的意义.对象是实际存在的该类事物的每一个个体,也被称为实例. 创建对象:包括声明对象和实例化对象 Person person;//声明 person = new ...

  9. sedgewick增量序列的希尔排序

    #include<bits/stdc++.h> using namespace std; int s[3]={1,5,19}; void shellsort(int *a,int n){ ...

  10. 【Best Time to Buy and Sell Stock III 】cpp

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...