Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15407   Accepted: 8889

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 大意:h,w分别为一个矩形的长和宽(h,m<=11),问用1*2的小矩形(可横竖摆放),问一共有多少种方法。 状态压缩,竖着摆放的小矩形占据该行的该位置和上一行对应位置,0表示该位置不摆放(即下一行竖着摆放的小矩形占据这个位置),1表示该位置摆放(横或竖)
   dfs(l+2,now<<2|3,pre<<2|3);   上下两行横着摆放
dfs(l+1,now<<1|1,pre<<1); 当前行竖着摆放,并占据上一行对应位置
dfs(l+1,now<<1,pre<<1|1); 上一行对应位置无论如何被占据,当前行由下一行竖着摆放的矩形占据
dfs搜出所有可能的路径path[num][2];path[i][0]存第i条路的当前状态,path[i][1]存第i条路的上一行状态。
剩下的dp很常规。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define LL long long int path[][];
LL dp[][<<];
int h,w,num;
void dfs(int l,int now,int pre)
{
if(l>w)
return;
if(l==w)
{
path[num][]=now;
path[num++][]=pre;
return;
}
dfs(l+,now<<|,pre<<|);
dfs(l+,now<<|,pre<<);
dfs(l+,now<<,pre<<|);
} int main()
{
while(scanf("%d%d",&h,&w)!=EOF&&h+w)
{
num=;
dfs(,,);
memset(dp,,sizeof(dp));
dp[][(<<w)-]=;
for(int i=;i<h;i++)
for(int j=;j<num;j++)
dp[i+][path[j][]]+=dp[i][path[j][]];
printf("%I64d\n",dp[h][(<<w)-]);
}
return ;
}

POJ_2411_Mondriaan's Dream_状态压缩dp的更多相关文章

  1. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

  2. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  3. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  4. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  5. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  6. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  7. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  8. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  9. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

随机推荐

  1. 【codeforces 785D】Anton and School - 2

    [题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...

  2. RBAC(Role-Based Access Control)

    http://hi.baidu.com/akini/blog/item/eddbd61b90f6d4fbae513371.html RBAC 求助编辑百科名片 基 于角色的访问控制(Role-Base ...

  3. [Usaco2014 Mar]Sabotage

    [Usaco2014 Mar]Sabotage 题目 Farmer John"s arch-nemesis, Farmer Paul, has decided to sabotage Far ...

  4. 暑假集训D17总结

    考试 玄学的一次考试= = T1乱搞 只会乱搞出前二十分  然后真的拿了二十分 T2模拟 自己造数据 没有一个是在十分钟内跳出来的 然后竟然A了 T3暴力 觉得如果老爷机心情不好就会被卡到20  然后 ...

  5. 【学QT】 3 - DEBUG集子

    1. [root@localhost helloqt]# make g++ -Wl,-rpath,/usr/local/qt/lib -o cfconv .obj/main.o .obj/cfconv ...

  6. GDB 调试 PHP文件

    http://www.bo56.com/%E5%9C%A82016%E7%9A%84phpcon%E5%A4%A7%E4%BC%9A%E4%B8%8A%E7%9A%84%E5%88%86%E4%BA% ...

  7. [PWA] Check Online Status by using the NavigatorOnLine API

    Even if you have your application fully cached, you couldn’t perform any external request without in ...

  8. Android --------- 自己定义VIew

    package com.example.coustomviewdemo; import android.R.interpolator; import android.content.Context; ...

  9. js中DOMContentLoaded和load的区别

    如题:DOMContentLoaded和load都是页面加载的时候触发的事件.区别在于触发的时机不一样. 浏览器渲染页面DOM文档加载的步骤: 1.解析HTML结构. 2.加载外部脚本和css文件. ...

  10. 详略。。设计模式1——单例。。。。studying

    设计模式1--单例 解决:保证了一个类在内存中仅仅能有一个对象. 怎么做才干保证这个对象是唯一的呢? 思路: 1.假设其它程序可以任意用new创建该类对象,那么就无法控制个数.因此,不让其它程序用ne ...