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

题目:

Mondriaan's Dream
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 15360 Accepted: 8861

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 2
1 3
1 4
2 2
2 3
2 4
2 11
4 11
0 0

Sample Output

1
0
1
2
3
5
144
51205
题目大意:给你一个已知长和宽的房间,让你用1*2和2*1的地板将其铺满,问有多少种方法可以实现

解题思路:
当在铺第i行时,需要考虑到第i-1行的情况还有当前行地板之间的距离,因此f[i][j]数组代表的就是当第i-1行已经铺满的情况下,第i行,用的情况为j覆盖的方案数,之后需要考虑的就是铺地板时需要考虑的三种情况,分别是:横着放,那么是因为上一行当前列及下一列没有空位,竖着放,那么上一行当前列就会空出空位,不放,那么就是上一行当前列没有位置。具体看代码

<span style="font-size:18px;">#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int i;
long long f[12][1<<12];///在前i-1行已经覆盖满的情况下,第i行用s情况覆盖的方案数
void dfs(int p,int now,int last)
{if(p>m) return;if(p==m)f[i][now]+=f[i-1][last];dfs(p+1,(now<<1)|1,(last<<1));///竖着放,会占据到当前列的上一行,因此通过左移让上一列的那个位置空出来dfs(p+1,(now<<1),(last<<1)|1);///不放,上一行当前的一列就为1dfs(p+2,(now<<2)|3,(last<<2)|3);///横着放,因为上一行当前列没有位置
}
int main()
{while(scanf("%d%d",&n,&m)&&n&&m){if(n%2&&m%2)///排除行列都为奇数的情况{printf("0\n");continue;}if(m>n)///让小的作为列swap(n,m);memset(f,0,sizeof(f));f[0][(1<<m)-1]=1;///第0行全部覆盖的方案数为1for( i=1;i<=n;i++){dfs(0,0,0);}cout<<f[n][(1<<m)-1]<<endl;}}
</span>
												

Mondriaan's Dream相关推荐

  1. POJ 2411 Mondriaan‘s Dream(最清楚好懂的状压DP讲解)(连通性状态压缩DP)

    poj 2411 Mondriaan's Dream(最清晰的状压DP解析) 闫氏DP大法好 我们这里是一列一列地来,因为是一个棋盘性的状态压缩DP,从哪个方向都一样 摆放的小方格总方案数 等价于 横 ...

  2. NC51189 Mondriaan‘s Dream

    NC51189 Mondriaan's Dream 题意: n * m的矩阵,用1 * 2和2 * 1的砖快密铺,问多少种方法: 题解: 方法1: 我们现在规定砖头的竖放的上部分为1,砖头的横放或者是 ...

  3. openjudge Mondriaan's Dream

    1413:Mondriaan's Dream 查看 提交 统计 提问 总时间限制:  3000ms  内存限制:  65536kB 描述 Squares and rectangles fascinat ...

  4. Mondriaan‘s Dream(状态压缩dp)

    问题 S: Mondriaan's Dream 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 [提交] [状态] [讨论版] [命题人:admin] 题目描述 Squa ...

  5. poj2411 Mondriaan's Dream (状压dp+多米诺骨牌问题)

    这道题的解析这个博客写得很好 https://blog.csdn.net/shiwei408/article/details/8821853 大致意思就是我们可以只处理两行之间的关系,然后通过这两个关 ...

  6. POJ 2411 Mondriaan's Dream [经典状态压缩dp]

    题意:略. 思路:这一题开始做的时候完全没有思路,便去看了别人的题解. 首先,对于这个题目解法想有一个初步的了解,请看这里:http://www.2cto.com/kf/201208/146894.h ...

  7. POJ - 2411 Mondriaan's Dream(状压dp)

    题目链接:点击查看 题目大意:铺瓷砖 题目分析:经典之经典的状态压缩动态规划,具体的懒得说了,怠惰ing..一个月之前写的代码,还好当时注释做的好,现在稍微一看就能立马理解,码到博客上存着吧,三种方法 ...

  8. POJ 2411 Mondriaan's Dream

    题意:用1*2的瓷砖拼出m*n的矩形.问有多少种拼法. 解法:设d[i][j]表示第i行状态为j的情况下,最多能有多少种拼法,对于状态j,1表示为竖着放置的瓷砖且它横跨i和i+1两行,其余皆用0表示. ...

  9. POJ 2411 Mondriaan's Dream(状态压缩DP)

    题目链接 早就见过这个题,开始以为有公式的,推了几次没推出,后来知道这个题是状态压缩DP.最近开始看状态压缩,本想试着解出来,但是这个比那个牛吃草复杂多了...位运算还是不是很熟练,这个题的解题报告有 ...

最新文章

  1. 有没有办法检查`null`和`undefined`?
  2. 认识OSSIM中的UUID
  3. deep learning with python 中文版-Deep Learning with Python
  4. shell脚本——系统变量 与 变量(定义 使用 只读 删除)
  5. Python进阶_wxpy学习:消息处理
  6. centos 删除crontab_centos7 定时任务crontab命令详解
  7. linux内核循环,模仿Linux内核kfifo实现的循环缓存
  8. java生成excel图表
  9. IntelliJ IDEA开发Java笔记
  10. war压缩命令_war包解压命令详解,java项目如何打包成war包?
  11. 产品经理如何看待NPDP认证?
  12. Security注解:@PreAuthorize,@PostAuthorize, @Secured
  13. 使用TTP224触摸芯片时出现的一些问题
  14. python基础语法Day11
  15. 输出字符的ascii码
  16. 华为:决定起诉美国政府
  17. 使用HTML+CSS+JS模拟比赛晋级的动画功能
  18. Web系统大规模并发—电商秒杀与抢购
  19. 【JavaScript 基础】-- 数组切割splice和slice
  20. zotero+谷歌翻译不能用,一招教你解决

热门文章

  1. html元素自动换行设置
  2. Google浏览器能否掘出另一块金山?
  3. 教育部:每所学校贷款项目总投资原则上不低于2000万
  4. (四)docker部署项目
  5. ACM中涉及到的数学知识
  6. 【转载】java报表工具报表软件选型经验总结分享
  7. QT-将应用程序打包成安装程序
  8. 中国内联热水器市场现状研究分析与发展前景预测报告
  9. 一球从M米高度自由下落,每次落地后返回原高度的一半,再落下。它在第N次落地时反弹多高?共经过多少米? 保留两位小数
  10. bio rad是哪个国家的的公司