题意:

给出n*m (1≤n、m≤11)的方格棋盘,用1*2的长方形骨牌不重叠地覆盖这个棋盘,求覆盖满的方案数。


Solution:

               位运算+状态压缩+dp

               二进制数(####)代表填完一行后这一行的状态,填满的地方为1,未填的地方为0。

               显然在填第i行时,能改变的仅为第i-1行和第i行,因此要满足在填第i行时,第1~i-2行已经全部填满。

               DFS一行的状态,要是填完第i行时,第i-1行被填满。

               因此两行的状态(p1,p2)满足,~p1=p2;

              

               DFS出所有满足条件的状态对(P1,P2)

               ①第i行第k位为1,第i-1行第k位为0。(一块骨牌竖直放置)

                         dfs(k+1,last<<1,now<<1 | 1)

               ②第i行第k位为0,第i-1行第k位为1。 (第i行空出第k位)

                         dfs(k+1,last<<1 | 1,now<<1)

               ③骨牌横向放置。

bfs (k + 2, last << 2 | 3, now << 2 | 3)

               

               转移方程:F[i][sp1]=∑f[i-1][sp2]

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#define LL long long
using namespace std;
int n, m, x;
LL f[12][1 << 12];
void dfs (int k, int last, int now) {
if (k ==m ) f[x][now] += f[x - 1][last];
if (k > m) return;
dfs (k + 1, last << 1, now << 1 | 1);
dfs (k + 1, last << 1 | 1, now << 1);
dfs (k + 2, last << 2 | 3, now << 2 | 3);
}
int main() {
while (~scanf ("%d %d", &n, &m) ) {
if (n == 0) break;
if (n > m) swap (n, m);
memset (f, 0, sizeof f);
f[0][ (1 << m) - 1] = 1;
for (x = 1; x <= n; x++)
dfs (0, 0, 0);
printf ("%lld\n", f[n][ (1 << m) - 1]);
}
}

  

POJ 2411.Mondriaan's Dream 解题报告的更多相关文章

  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)

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

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

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

  5. [POJ] 2411 Mondriaan's Dream

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

  6. [poj 2411]Mondriaan's Dream (状压dp)

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

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

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

  8. poj 2411 Mondriaan's Dream 轮廓线dp

    题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...

  9. poj 2411 Mondriaan's Dream(状态压缩dP)

    题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...

随机推荐

  1. 【HDOJ】1813 Escape from Tetris

    bfs预处理一点到边界的最小距离,IDA*求出可行方案.注意按字典序初始化dir数组.并且存在中间点全为1,边界含0的可能性(wa了很多次).此时不输出任何命令. /* 1813 */ #includ ...

  2. 【转】color颜色十六进制编码大全

    原文网址:http://blog.csdn.net/coder_pig/article/details/18262105 最近刚开始学web,发现好的颜色搭配可以让自己的网页更加美观, 中午不想做事, ...

  3. 连接Oracle的几种方式

    如何引用Data.OracleClient.dll 由于从.net 4.0之后,微软将OracleClient.dll从框架里去除了,所以要使用,需要在VS2010里面去把项目的.net框架从.net ...

  4. cf702A Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Apache-Tika解析Excell文档

    通常在使用爬虫时,爬取到网上的文章都是各式各样的格式处理起来比较麻烦,这里我们使用Apache-Tika来处理Excell格式的文章,如下: package com.mengyao.tika.app; ...

  6. segment

    1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlStyle) { UISegm ...

  7. 一个美国小券商的生存之道Tradestation

    转自:证券时报记者 张欣然 桂衍民 中国互联网金融的口号喊了十几年,众多证券公司仍然苦于找不到新的蓝海,研究大西洋彼岸的美国TradeStation公司的业务模式,也许对国内的证券公司会有一些启迪. ...

  8. 一个urllib2构建的html下载器的代理组件的实现方案

    调用栈/函数链如下: 情形一:下载器初始化时 __init__ buildOpener#构建opener newProxy4Opener#装备代理 getNewProxy#获取代理 maintainP ...

  9. IntelliJ IDEA安装 一些配置

    idea 配置修改 本篇 参考https://blog.liyang.io/234.html. 1.修改IDEA菜单的字体大小: 单击File | Project Structure菜单项,打开Pro ...

  10. swfit-小知识Demo

    知识点: 重写方法.属性,自动引用计数,throws异常抛出,滚动视图,扩展语法,协议,计时器,UserDefaultsgit项目地址: https://github.com/lu459700780/ ...