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. bzoj 2818 GCD 数论 欧拉函数

    bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Samp ...

  2. bzoj1086 [SCOI2005]王室联邦 树分块

    [bzoj1086][SCOI2005]王室联邦 2014年11月14日2,6590 Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的 ...

  3. html5的新通讯技术socket.io,实现一个聊天室

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://xxxxxx

    读取T卡文件里的域名,HTTP请求出现如下错误 java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ...

  5. hdu3853:LOOPS

    题目大意:r*c个点,每个点有Aij的概率回到自己本身,Bij的概率向右一格,Cij的概率向下一格,求从(1,1)到(r,c)的期望步数. 题解:有了hdu4405的经验,从后往前推期望.那么,E(i ...

  6. BZOJ1916: [Usaco2010 Open]冲浪

    n<=50000个点m<=150000的带边权DAG,保证1入度0,n出度0,其他点入度出度均不为0,求:从一号点开始到n,期间有可能K<=10次随机选边走,最坏情况下总边权多少. ...

  7. django学习之- 信号

    - Django内置的信号Model signals pre_init # django的modal执行其构造方法前,自动触发 post_init # django的modal执行其构造方法后,自动触 ...

  8. HDU 6396 贪心+优先队列+读入挂

    Swordsman Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  9. 最近公共祖先(Least Common Ancestors)

    题意: 给定一棵有根树T,给出若干个查询lca(u, v)(通常查询数量较大),每次求树T中两个顶点u和v的最近公共祖先,即找一个节点,同时是u和v的祖先,并且深度尽可能大(尽可能远离树根).通常有以 ...

  10. I NEED A OFFER!---hdu1203(01背包)

     http://acm.hdu.edu.cn/showproblem.php?pid=1203   Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考 ...