Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 12854   Accepted: 7486

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*n的棋盘,考虑第一个骨牌的方法,要么两个横着放,要么一个竖着放,
如果是n*m的棋盘,那么它还是可以用2*n的棋盘(每两行)递推过去的,每行(包括第一行)有三种选择,横着放,竖着放,
不放,如果用1表示横着放和竖着放的第二个,0表示竖着放的第一个和不放,每次都是两行之间的转换,
找出可以互相转换的状态就可以,采用深搜,
设pre和now,
如果当前位置横着放,状态为11,那么上一行也必须是11
如果当前位置竖着放,状态为1,上一行为0
如果当前位置不放,那么上一行此位置为1,当前位置为0
,然后从第0行全为1开始,因为这样转换之后的状态才能构成一个完整的棋盘。
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 12
#define LL long long
using namespace std;
int h,w;
LL d[maxn][<<maxn];
LL cnt;
LL EX[][];
void dfs(int l,int now,int pre)
{
if(l>w)
return ;
if(l==w)
{
EX[cnt][]=pre;
EX[cnt++][]=now;
//cout<<pre<<" "<<now<<endl;
return ;
}
dfs(l+,((now<< )|),((pre<<) | )) ; //横放
dfs(l+,((now<<) |),(pre<<) ) ; //竖放
dfs(l+, (now<<) , ((pre<<)| )) ; //不放
}
void solve()
{
int s=(<<w)-;
d[][s]=;
for(int i=;i<h;i++)
for(int j=;j<cnt;j++)
{
d[i+][EX[j][]]+=d[i][EX[j][]];
}
// for(int j=0;j<cnt;j++)
// printf("%d %d\n",EX[j][1],EX[j][0]);
printf("%lld\n",d[h][s]);
}
int main()
{
while(~scanf("%d%d",&h,&w) && (h!= && w!=))
{
memset(d,,sizeof(d));
// if(h>w)
// swap(h,w);
cnt=;
dfs(,,);
solve();
}
return ;
}
 

poj 2411((多米诺骨牌问题))的更多相关文章

  1. poj 1717==洛谷P1282 多米诺骨牌

    Dominoes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6571   Accepted: 2178 Descript ...

  2. 【Tsinghua OJ】多米诺骨牌(domino)问题

    (domino.c/cpp)[问题描述] 小牛牛对多米诺骨牌有很大兴趣,然而她的骨牌比较特别,只有黑色和白色的两种.她觉 得如果存在连续三个骨牌是同一种颜色,那么这个骨牌排列便是不美观的.现在她有n个 ...

  3. 省选训练赛第4场D题(多米诺骨牌)

    题目来自FZU2163 多米诺骨牌 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Vasya很喜欢排多米诺 ...

  4. 【01背包】洛谷P1282多米诺骨牌

    题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...

  5. 多米诺骨牌放置问题(状压DP)

    例题: 最近小A遇到了一个很有趣的问题: 现在有一个\(n\times m\)规格的桌面,我们希望用\(1 \times 2\)规格的多米诺骨牌将其覆盖. 例如,对于一个\(10 \times 11\ ...

  6. P1282 多米诺骨牌 (背包变形问题)

    题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...

  7. [LeetCode] Push Dominoes 推多米诺骨牌

    There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...

  8. P1282 多米诺骨牌

    P1282 多米诺骨牌 题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S ...

  9. [Luogu1282]多米诺骨牌(DP)

    #\(\color{red}{\mathcal{Description}}\) \(Link\) 我们有一堆多米诺骨牌,上下两个部分都有点数,\(But\)我们有一个操作是可以对调上下的点数.若记一块 ...

  10. 「ZJOI2009」多米诺骨牌

    「ZJOI2009」多米诺骨牌 题目描述 有一个n × m 的矩形表格,其中有一些位置有障碍.现在要在这个表格内 放一些1 × 2 或者2 × 1 的多米诺骨牌,使得任何两个多米诺骨牌没有重叠部分,任 ...

随机推荐

  1. 【贪心】codeforces B. Heidi and Library (medium)

    http://codeforces.com/contest/802/problem/B [题意] 有一个图书馆,刚开始没有书,最多可容纳k本书:有n天,每天会有人借一本书,当天归还:如果图书馆有这个本 ...

  2. 洛谷 P 1018 乘积最大 ==Codevs

    题目描述 今年是国际数学联盟确定的“2000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一个好朋友XZ也有幸得 ...

  3. msp430入门编程17

    msp430中C语言的寄存器操作 msp430入门学习 msp430入门编程

  4. Python()-类命名空间和对象/实例命名空间

    类命名空间和对象/实例命名空间: 创建类, 就会创建一个类的名称空间, 空间:存储类的属性 属性: 静态属性:直接定义在类下面 & 和类名关联 的变量 对象属性:在类内和self关联 & ...

  5. 洛谷—— P1098 字符串的展开

    https://www.luogu.org/problem/show?pid=1098 题目描述 在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中,含有类 ...

  6. html页面中拍照和上传照片那些事儿(一)

    本文为原创,转载请注明出处: cnzt  文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6709037.html  一. 思路: <input type= ...

  7. [转] SQL SERVER 2008 R2 安装中的账户设置问题

    故纸堆 原文:SQL SERVER 2008安装中设置账户的问题,2013-7 在安装SQL Server 2008数据库服务器的时候,服务器有可能处于以下几种环境中: ①工作组环境下的服务器 (Wo ...

  8. Windows下SVN服务器及客户端的使用

    原文地址:windows下配置VisualSVN Server服务器 作者:Deem_passion 下载安装文件: 服务端安装文件:VisualSVN-Server-1.6.2 客户端安装文件:To ...

  9. linux字符驱动之poll机制按键驱动

    在上一节中,我们讲解了如何自动创建设备节点,实现一个中断方式的按键驱动.虽然中断式的驱动,效率是蛮高的,但是大家有没有发现,应用程序的死循环里的读函数是一直在读的:在实际的应用场所里,有没有那么一种情 ...

  10. 【APUE】进程间通信之共享存储(mmap函数)

    共享内存可以说是最有用的进程间通信方式,也是最快的IPC形式,因为进程可以直接读写内存,而不需要任何数据的拷贝.对于像管道和消息队列等通信方式,则需要在内核和用户空间进行四次的数据拷贝,而共享内存则只 ...