题目:http://poj.org/problem?id=2411

Input

The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.

Output

For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.

题意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种。

思路:一道很经典的状态dp,但是还是很难想,横着放定义为11,竖着放定义为01.

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. using namespace std;
  6. __int64 d[][<<], f[<<];//用———int64,因为有可能数很大
  7. int h, w, full;
  8.  
  9. bool ok(int x) //判断一行里是否出现连续奇数个1,第一行的话不允许
  10. {
  11. int sum = ;
  12. while(x>)
  13. {
  14. if((x&)==)
  15. sum++;
  16. else
  17. {
  18. if((sum&)==)
  19. return false;
  20. sum = ;
  21. }
  22. x = (x>>);
  23. }
  24. if((sum&)==)
  25. return false;
  26. return true;
  27. }
  28. bool check(int x1, int x2)
  29. {
  30. int xx = (<<w)-;
  31. if((x1|x2)==xx&&f[x1&x2])//去掉竖着00和竖着单独11的情况,一定不要忘了单独11的情况
  32. return true;
  33. return false;
  34. }
  35. int main()
  36. {
  37. int i, j, k;
  38. memset(f, , sizeof(f));
  39. full = (<<);
  40.  
  41. for(i = ; i < full; i++)
  42. if(ok(i))
  43. f[i] = ; //记录连续的奇数个1
  44. while(~scanf("%d%d", &h, &w))
  45. {
  46. if(h==&&w==)
  47. break;
  48. full = (<<w);
  49. memset(d, , sizeof(d));
  50. for(i = ; i < full; i++)
  51. if(f[i])
  52. d[][i] = ;
  53.  
  54. for(k = ; k < h; k++)
  55. for(i = ; i < full; i++)
  56. for(j = ; j < full; j++)
  57. {
  58. if(check(i, j))
  59. d[k][i] += d[k-][j];
  60. }
  61. printf("%I64d\n", d[h-][full-]); //最后一行,而且满1
  62. }
  63. return ;
  64. }

poj 2411 Mondriaan's Dream(状态压缩dP)的更多相关文章

  1. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

  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)

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

  4. 【poj2411】Mondriaan's Dream 状态压缩dp

    AC传送门:http://vjudge.net/problem/POJ-2411 [题目大意] 有一个W行H列的广场,需要用1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法? [题解] 对于 ...

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

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

  6. POJ2411 - Mondriaan's Dream(状态压缩DP)

    题目大意 给定一个N*M大小的地板,要求你用1*2大小的砖块把地板铺满,问你有多少种方案? 题解 刚开始时看的是挑战程序设计竞赛上的关于铺砖块问题的讲解,研究一两天楞是没明白它代码是怎么写的,智商捉急 ...

  7. poj 2411 Mondriaan's Dream (轮廓线DP)

    题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...

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

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

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

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

随机推荐

  1. Zabbix实现告警分级

    Zabbix中trigger的severity的值定义了trigger的不同严重程度,其中severity默认的6个值为 Not classified, Information, Warning, A ...

  2. [resource]Python机器学习库

    reference: http://qxde01.blog.163.com/blog/static/67335744201368101922991/ Python在科学计算领域,有两个重要的扩展模块: ...

  3. Linux开机执行bash脚本

    问题描述:     Linux开机执行bash脚本     问题解决:         (1)在 /etc/init.d文件夹中新建一个脚本myinit                     (2) ...

  4. hlsl 的tex函数

    texCUBE http://msdn.microsoft.com/en-us/library/windows/desktop/bb509687(v=vs.85).aspx

  5. PHP之set_error_handler()函数讲解

    定义和用法 set_error_handler() 函数设置用户自定义的错误处理函数. 该函数用于创建运行时期间的用户自己的错误处理方法. 该函数会返回旧的错误处理程序,若失败,则返回 null. 语 ...

  6. hdu 4888

    网络流建模,建模不难,难在找环: #include<cstdio> #include<algorithm> #include<vector> #include< ...

  7. C语言关键字register、extern、static

    C语言中: 一.register变量 关键字regiter请求编译器尽可能的将变量存在CPU的寄存器中.有以下几点注意的地方. register变量必须是能被CPU寄存器所接受的类型,这通常意味着re ...

  8. hdu 3336 Count the string(思维可水过,KMP)

    题目 以下不是KMP算法—— 以下是kiki告诉我的方法,好厉害的思维—— 就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找. #include<stdio.h> # ...

  9. ***解决PHP输出多余的空格或换行

    用CI框架写APP后台接口的时候,返回的JSON前面有多余的2哥换行,首先排查的是BOM,结果问题依旧 再就是排查<?php ?> 标签外没有多余的回车.换行,结果发现确实有多余的换行,去 ...

  10. lintcode :搜索旋转排序数组

    题目 搜索旋转排序数组 假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2).给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引 ...