题意:

给出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]

代码:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #define LL long long
  5. using namespace std;
  6. int n, m, x;
  7. LL f[12][1 << 12];
  8. void dfs (int k, int last, int now) {
  9. if (k ==m ) f[x][now] += f[x - 1][last];
  10. if (k > m) return;
  11. dfs (k + 1, last << 1, now << 1 | 1);
  12. dfs (k + 1, last << 1 | 1, now << 1);
  13. dfs (k + 2, last << 2 | 3, now << 2 | 3);
  14. }
  15. int main() {
  16. while (~scanf ("%d %d", &n, &m) ) {
  17. if (n == 0) break;
  18. if (n > m) swap (n, m);
  19. memset (f, 0, sizeof f);
  20. f[0][ (1 << m) - 1] = 1;
  21. for (x = 1; x <= n; x++)
  22. dfs (0, 0, 0);
  23. printf ("%lld\n", f[n][ (1 << m) - 1]);
  24. }
  25. }

  

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. Maven实战五

    转载:http://www.iteye.com/topic/1123232 我们项目中用到的jar包可以通过依赖的方式引入,构建项目的时候从Maven仓库下载即可. 1. 依赖配置    依赖可以声明 ...

  2. java学习之函数

    讲完了语句结构还有运算符.变量,下面我们来了解下函数. 那么什么是函数,函数的定义是怎样的呢? 函数的定义: 函数是指在类当中定义的一段有特殊功能的代码段,同时函数在类中也被成为方法. class F ...

  3. CF 85D Sum of Medians (五颗线段树)

    http://codeforces.com/problemset/problem/85/D 题意: 给你N(0<N<1e5)次操作,每次操作有3种方式, 1.向集合里加一个数a(0< ...

  4. 数据结构(二维线段树,差分): NOI2012 魔幻棋盘

    貌似想复杂了…… #include <iostream> #include <cstring> #include <cstdio> #define mid ((l+ ...

  5. 图论(网络流):SPOJ OPTM - Optimal Marks

    OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...

  6. openfire for mac 无法启动

    http://blog.csdn.net/winer888/article/details/49886281 ①:sudo chmod -R 777 /usr/local/openfire/bin ② ...

  7. Python算法之---冒泡,选择,插入排序算法

    ''' Created on 2013-8-23    @author: codegeek '''    def bubble_sort(seq):     for i in range(len(se ...

  8. android编程中setLayoutParams方法设置

    第一篇 private LinearLayout generateHeadOfControl() { LinearLayout LayoutHead = createLayout(LinearLayo ...

  9. Android ViewPager FragmentPagerAdapter

    ViewPager  里面放Fragment <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  10. static对象的高级用法

    1. 函数里static对象是local的,其他如全局对象,类里的static对象都是非local的,会在程序初始化中提前创建 2. 非local的对象的创建无法确定先后次序,但能保证在main函数前 ...