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. 51nod1040 最大公约数之和

    求$\sum_{i=1}^{n}(i,n)$.n<=1e9. $\sum_{i=1}^{n}(i,n)=\sum_{d|n}d\sum_{i=1}^{n}[(i,n)=d]=\sum_{d|n} ...

  2. BZOJ2196: [Usaco2011 Mar]Brownie Slicing

    n<=500 * m<=500的方阵,先沿横坐标切A-1刀,再把每一块切B-1刀,得到A*B块,求这A*B块的数字之和的最小值的最大值. 最小值最大--二分,然后贪心切.每次扫一行,看这一 ...

  3. BMP格式,转载

    BMP文件格式,又称为Bitmap(位图)或是DIB(Device-Independent Device,设备无关位图),是Windows系统中广泛使用的图像文件格式.由于它可以不作任何变换地保存图像 ...

  4. Android Notification通知简介

    Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...

  5. 洛谷——P2434 [SDOI2005]区间

    P2434 [SDOI2005]区间 题目描述 现给定n个闭区间[ai, bi],1<=i<=n.这些区间的并可以表示为一些不相交的闭区间的并.你的任务就是在这些表示方式中找出包含最少区间 ...

  6. Java加载配置文件类

    /** *  对应配置文件类, */ package com.up72.parkSys.ThirdParty; import java.io.IOException;import java.io.In ...

  7. html5 拖拽元素

    利用html5实现元素的拖拽,让拖动元素在指定的容器中拖动. 注意点:1.被拖元素要设置拖动属性.draggable="true" 2.容器元素要设置阻止默认事件处理 实现效果图如 ...

  8. cmd的操作命令导出导入.dmp文件

    利用cmd的操作命令导出,详情如下(备注:方法二是转载网上的教程): 1:G:\Oracle\product\10.1.0\Client_1\NETWORK\ADMIN目录下有个tnsname.ora ...

  9. 使用Guava适配不同的callback

    Cache<Key,Value> cache =CacheBuilder.newBuilder() .maximumSize(1000) .build();// look Ma, no C ...

  10. zedboard硬件连接过程

    1.      ZedBoard – Connect a 2nd micro-USBcable between the host machine and connector J17 (JTAG) 2. ...