Mondriaan's Dream

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 17187   Accepted: 9911

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

Source

 
 //2017-08-02
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
int n, m;
long long dp[N][<<N];//dp[col][state]表示第col列,在state状态下(即前一列对该列的影响)的方法数。 //dfs表示当前处理到col列的第i个格子,state状态下,对下一列的影响nex
void dfs(int col, int i, int state, int nex){
if(i == n){
dp[col+][nex] += dp[col][state];
return;
}
if((state&(<<i)) > )//这个格子已经被上一列填过
dfs(col, i+, state, nex);
if((state&(<<i)) == )//格子没有被填充,尝试横着放一块砖
dfs(col, i+, state, nex|(<<i));
if(i+<n && (state&(<<i))== && (state&(<<(i+)))==)//尝试竖着放一块砖
dfs(col, i+, state, nex);
} int main(){
while(cin>>n>>m){
if(!n && !m)break;
memset(dp, , sizeof(dp));
dp[][] = ;
for(int col = ; col <= m; col++){
for(int state = ; state < (<<n); state++){
if(dp[col][state])
dfs(col, , state, );
}
}
cout<<dp[m+][]<<endl;//答案为第m+1列,前一列对其影响为0的方法数。
} return ;
}

POJ2411(SummerTrainingDay02-I 状态压缩dp)的更多相关文章

  1. 状态压缩dp(hdu2167,poj2411)

    hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...

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

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

  3. SGU131 - Hardwood floor(状态压缩DP)

    题目大意 给定一个N*M大小的矩形,要求你用1*2和2*2(缺个角)的砖块把矩形铺满(不能重叠),问总共有多少种铺法? 题解 受POJ2411的影响,怎么都没想到3,4,5,6这几种情况该怎么放置,看 ...

  4. 状态压缩DP(大佬写的很好,转来看)

    奉上大佬博客 https://blog.csdn.net/accry/article/details/6607703 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的 ...

  5. hoj2662 状态压缩dp

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

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

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

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

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

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

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

  9. 状态压缩dp问题

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

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

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

随机推荐

  1. ss的使用配置(电脑、手机FQ)

    注:FQ仅用于google查阅资料等,禁止违规违法行为 自己搭建ss服务 1.vps购买:https://www.alpharacks.com/holiday 按流程填完相关信息(Operating ...

  2. 05-01 Java 方法

    方法 方法定义.格式: /* 方法:完成特定功能的代码块. 注意:在很多语言里面有函数的定义,而在Java中函数被称为方法. 方法格式: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数 ...

  3. 关于Python2和Python3之间的文本模型改变

    原文地址:http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#what-act ...

  4. Linux机器之间复制文件和目录方式&Linux的scp命令详解

    本文转载于:http://www.cnblogs.com/hitwtx/archive/2011/11/16/2251254.html 整理总结如下: 不同的Linux之间copy文件常用有3种方法: ...

  5. Git for Windows之基础环境搭建与基础操作

    一.安装Git工具 下载地址:Git For Windows 下载完后,安装,全程Next. 二.全局配置 1.配置本地用户名,用于提交代码 2.配置邮箱 三.创建本地Git项目仓库 1.建立代码仓库 ...

  6. Qt中QMenu的菜单关闭处理方法

    Qt中qmenu的实现三四千行... 当初有个特殊的需求, 要求菜单的周边带几个像素的阴影, 琢磨了半天, 用QMenu做不来, 就干脆自己用窗口写一个 然而怎么让菜单消失却非常麻烦 1. 点击菜单项 ...

  7. SSL编程(2).NET最简单的客户端

      在Windows平台上,实现SSL的.NET类是System.Net.Security.SslStream类.这个类既可以用于建立SSL服务,也可以用来作为SSL客户端连接远端的SSL服务. 最简 ...

  8. 【LeetCode题解】3_无重复字符的最长子串(Longest-Substring-Without-Repeating-Characters)

    目录 描述 解法一:暴力枚举法(Time Limit Exceeded) 思路 Java 实现 Python 实现 复杂度分析 解法二:滑动窗口(双指针) 思路 Java 实现 Python 实现 复 ...

  9. java面向对象基础(三):对象转型和多态

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  10. C# ABP 配置连接数据库&创建表

    1. 配置连接数据库 配置连接数据库很简单,只需要打开Web项目,然后找到Web.config,配置如下: <connectionStrings> <add name="D ...