F - Mondriaan's Dream

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2014-05-15)

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 压缩时,0是横放或竖放的下半部分,1是竖放的上半部分。
注意:
要用long long;
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<set> #define N 1130
#define M 15
#define inf 1000000007
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int h,w;
ll dp[][ (<<)+ ];
int s[];
ll ans; void ini()
{
memset(dp,,sizeof(dp));
ans=;
} int check(int o)
{
int cou=;
//int flag=1;
int j=;
for(j=;j<w;j++){
s[j]=o%;
o/=;
}
j=;
while(j<w)
{
while(s[j]== && j<w) j++;
cou=;
while(s[j]== && j<w){
cou++;j++;
}
if(cou%==) return ;
}
if(cou%==) return ;
return ;
} void solve()
{
int o,i,p,te;
if(h*w%==) return;
for(o=;o<(<<w);o++){
if( check(o)== ) continue;
dp[][o]=;
// printf(" o=%d\n",o);
} for(i=;i<h;i++){
for(o=;o<(<<w);o++){
for(p=;p<(<<w);p++){
if( (p&o)!= ) continue;
te=o | p;
if( check(te)== ) continue;
dp[i][o]+=dp[i-][p];
}
}
} for(p=;p<(<<w);p++){
if( check(p)== ) continue;
dp[h][]+=dp[h-][p];
}
ans=dp[h][];
} void out()
{
printf("%I64d\n",ans);
} int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
// for(int cnt=1;cnt<=T;cnt++)
// while(T--)
while(scanf("%d%d",&h,&w)!=EOF)
{
if(h== && w==) break;
ini();
solve();
out();
}
return ;
}

POJ 2411 状压dp的更多相关文章

  1. POJ 2411 状压DP经典

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16771   Accepted: 968 ...

  2. POJ 3254 (状压DP) Corn Fields

    基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...

  3. poj 1170状压dp

    题目链接:https://vjudge.net/problem/POJ-1170 题意:输入n,表示有那种物品,接下来n行,每行a,b,c三个变量,a表示物品种类,b是物品数量,c代表物品的单价.接下 ...

  4. POJ 3254 状压DP

    题目大意: 一个农民有一片n行m列 的农场   n和m 范围[1,12]  对于每一块土地 ,1代表可以种地,0代表不能种. 因为农夫要种草喂牛,牛吃草不能挨着,所以农夫种菜的每一块都不能有公共边. ...

  5. poj 3254 状压dp入门题

    1.poj 3254  Corn Fields    状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...

  6. poj 1185(状压dp)

    题目链接:http://poj.org/problem?id=1185 思路:状态压缩经典题目,dp[i][j][k]表示第i行状态为j,(i-1)行状态为k时最多可以放置的士兵个数,于是我们可以得到 ...

  7. poj 2923 状压dp+01背包

    好牛b的思路 题意:一系列物品,用二辆车运送,求运送完所需的最小次数,两辆车必须一起走 解法为状态压缩DP+背包,本题的解题思路是先枚举选择若干个时的状态,总状态量为1<<n,判断这些状态 ...

  8. Islands and Bridges(POJ 2288状压dp)

    题意:给你一个图和每个点的价值,边权值为连接两点权值的积,走哈密顿通路,若到达的点和上上个点相连则价值加三点乘积,求哈密顿通路的最大价值,和最大价值哈密顿通路的条数. 分析:开始看这个题很吓人,但想想 ...

  9. Hie with the Pie(POJ 3311状压dp)

    题意:披萨店给n个地方送披萨,已知各地方(包括披萨店)之间花费的时间,求送完所有地方并回到店花费的最小时间 分析:状态好确定dp[i][j],i中1表示地方已送过,否则为0,j为当前状态最后一个送过的 ...

随机推荐

  1. UVA 1412 Fund Management (预处理+状压dp)

    状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...

  2. 使用prelu

    一个使用方式:http://blog.csdn.net/xg123321123/article/details/52610919 还有一种是像relu那样写,我就是采用的这种方式,直接把名字从relu ...

  3. MFC:AfxParseURL

    BOOL AFXAPI AfxParseURL(     LPCTSTR pstrURL,     DWORD& dwServiceType,     CString& strServ ...

  4. 项目中多条数据保存的json实例

    //js代码function checkCode(num){ var typeid = $("#typeid").val(); if(typeid == "") ...

  5. NOIP 成绩

    这道题中点是在小数上,因为成绩可能是:“95.5 87.7……”所以我们就要用:printf和scanf这样就可以控制小数了!!! code: #include<bits/stdc++.h> ...

  6. Spring Boot + Mybatis + Druid 动态切换多数据源

    在大型应用程序中,配置主从数据库并使用读写分离是常见的设计模式. 在Spring应用程序中,要实现读写分离,最好不要对现有代码进行改动,而是在底层透明地支持. 这样,就需要我们再一个项目中,配置两个, ...

  7. perl学习之:shift/unshift

    perl中shift 和unshift 操作 2008-02-02 11:18:04|  分类: Perl语言|举报|字号 订阅     ############################### ...

  8. linux下ls出现文件的后缀有@,* ,/之类的解释

    ls -Fafptool*  img_maker*    lzcmp@     lzfgrep@   lzma*         lzmore*         node-pre-gyp@bower@ ...

  9. 00031_ArrayList集合中常用的方法

    1.ArrayList集合提供的一些常用方法 import java.util.ArrayList; public class ArrayListDemo01 { public static void ...

  10. joyoi2020/lfyzoj114 Rainbow 的信号

    位与位间互不影响.一位一位计算. 长度为 \(1\) 的区间,选出概率为 \(1/n^2\).其余区间,选出概率为 \(2/n^2\).(这里的区间 \(l \leq r\)) 枚举右端点.记 \(l ...