Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 13519   Accepted: 7876

Description

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.

Expert as he was in this
material, he saw at a glance that he'll need a computer to calculate the number
of ways to fill the large rectangle whose dimensions were integer values, as
well. Help him, so that his dream won't turn into a nightmare!

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.

Sample Input

  1. 1 2
  2. 1 3
  3. 1 4
  4. 2 2
  5. 2 3
  6. 2 4
  7. 2 11
  8. 4 11
  9. 0 0

Sample Output

  1. 1
  2. 0
  3. 1
  4. 2
  5. 3
  6. 5
  7. 144
  8. 51205

Source

题目大意:给一个n,m,问n乘m的矩形用1*2的矩形填,填满有多少种方式
ac代码
196K 16MS
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define LL __int64
  4. LL dp[2][1<<12];
  5. int n,m;
  6. LL add;
  7. void dfs(int i,int p,int pos)
  8. {
  9. if(pos==m)
  10. {
  11. dp[i][p]+=add;
  12. return;
  13. }
  14. dfs(i,p,pos+1);
  15. if(pos<m-1&&!(p&(1<<pos))&&!(p&(1<<(pos+1))))
  16. {
  17. dfs(i,p|(1<<pos)|(1<<(pos+1)),pos+2);
  18. }
  19. }
  20. int main()
  21. {
  22. while(scanf("%d%d",&n,&m)!=EOF,n||m)
  23. {
  24. if(n*m%2)
  25. {
  26. printf("0\n");
  27. continue;
  28. }
  29. int rt=(1<<m)-1;
  30. memset(dp,0,sizeof(dp));
  31. add=1;
  32. dfs(0,0,0);
  33. int i,j;
  34. for(i=1;i<n;i++)
  35. {
  36. memset(dp[i%2],0,sizeof(dp[i%2]));
  37. for(j=0;j<=rt;j++)
  38. {
  39. if(dp[(i-1)%2][j])
  40. {
  41. add=dp[(i-1)%2][j];
  42. dfs(i%2,~j&rt,0);
  43. }
  44. }
  45. }
  46. printf("%I64d\n",dp[(n-1)%2][rt]);
  47. }
  48. }

  

POJ 题目2411 Mondriaan's Dream(状压DP)的更多相关文章

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

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

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

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

  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)

    状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...

  5. POJ 2411 Mondriaan'sDream(状压DP)

    题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...

  6. POJ 3311 Hie with the Pie (状压DP)

    dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推 ...

  7. POJ 1321 棋盘问题(DFS & 状压DP)

    用DFS写当然很简单了,8!的复杂度,16MS搞定. 在Discuss里看到有同学用状态压缩DP来写,就学习了一下,果然很精妙呀. 状态转移分两种,当前行不加棋子,和加棋子.dp[i][j]中,i代表 ...

  8. POJ:1185-炮兵阵地(状压dp入门)

    炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组 ...

  9. poj 2404 中国邮递员问题 欧拉回路判定+状压dp

    /* 状压dp 邮递员问题:求经过任意点出发经过每一条边一次并回到原点. 解法:1.如果是欧拉回路那么就是所有的边的总和. 2.一般的解法,找出所有的奇度顶点,任意两个顶点匹配,即最小完美匹配,可用状 ...

随机推荐

  1. jQuery get() 函数

    get() 函数 用于获取当前jQueryobject对象所匹配的DOM元素 语法 jQueryobject.get(index)//因为在JQuery中.很多时候和[]等价所以jQueryobjec ...

  2. Ajax聊天

    结构: index.html <!DOCTYPE html> <html> <head> <title>index.html</title> ...

  3. Hibernate连数据库

    1.建数据库,建表(一定要设主码) create database Hibernate create table Students( sno char(10) primary key, sna cha ...

  4. flask笔记1-安装

    1.创建应用的根目录: 2.在根目录下创建独立的虚拟python运行环境,创建完成后当前目录会有一个文件夹,即该独立环境(使用--no-site-pachages参数将不会复制任何系统python环境 ...

  5. Sql Server R2还有备份数据库错误

    错误信息描述  该数据库是运行版本10.50.1600的服务器上备份的.该版本与此服务器(运行版本10.00.1600)不兼容.请在支持该被份的服务器上还原该数据,  或者使用与此服务器兼容的备份(M ...

  6. C++中的const和指针组合

    在C++里,const修饰指针有以下三种情况 (1)指针常量:即指向常量的指针 const  int *p或者int const *p const在*前,,可以这样理解它的功能,因为const在*前, ...

  7. mybatis if test 不为空字符串或null

    <if test="type !=null and type !=''"> AND l.type=#{type,jdbcType=INTEGER} </if> ...

  8. Scala学习 —— 元组&映射

    再说集合之前,我们先来回顾一下映射&元祖 映射是键/值对偶的集合,Scala有一个通用的叫法--元组,也就是n个对象的聚集,并不一定要相同类型的.对偶不过是一个n=2的元祖.元祖对于那种需要将 ...

  9. WinForm 菜单和工具栏

    菜单和工具栏: 1.MenuStrip:顶部菜单 优先级最高,默认在最顶部 (1)分割线:a.打一个减号 “-”                   b.右键插入Separator (2)点击事件:每 ...

  10. javascript实现列表的点击展开折叠

    <script> window.onload = function() { //要折叠的区域 var catalog = document.getElementById("div ...