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. JavaScript基础(1)-ECMAScript

    一.JavaScript简介 1.JavaScript历史背景 布兰登 • 艾奇(Brendan Eich,1961年-),1995年在网景公司,发明的JavaScript. 刚开始JavaScrip ...

  2. fatal: LF would be replaced by CRLF in index.html

    进入项目目录,在.git文件夹下打开config配置文件,添加上下面两句话: autocrlf = false safecrlf = false 即可

  3. [转载]SystemD strikes again : Unit X.mount is bound to inactive unit

    http://mamchenkov.net/wordpress/2017/11/09/systemd-strikes-again-unit-var-whatever-mount-is-bound-to ...

  4. 交换机与VLAN

    1. 交换机 1.1 定义 交换机是一种基于MAC地址识别,能完成封装转发数据帧功能的网络设备. HUB集线器是一种物理层共享设备,HUB本身不能识别MAC 地址和IP地址,当同一局域网内的A主机给B ...

  5. mongodb postgresql mysql jsonb对比

    mongodb pg mysql jsonb对比 http://erthalion.info/2017/12/21/advanced-json-benchmarks/ 使用禁用jsonb列的压缩 AL ...

  6. [原创]K8正方系统密码解密工具

    工具: K8_zfsoftDecode编译: 自己查壳组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8.blog.163.com发布: 2015/8/1 1 ...

  7. cAdvisor+InfluxDB+Grafana 监控Docker

    容器的监控方案其实有很多,有docker自身的docker stats命令.有Scout.有Data Dog等等,本文主要和大家分享一下比较经典的容器开源监控方案组合:cAdvisor+InfluxD ...

  8. POJ 2501

    #include<iostream> #include<iomanip> #include<stdio.h> #include<string> #inc ...

  9. Pycharm PEP8代码编写规范 选择性忽略

    http://pep8.readthedocs.io/en/latest/intro.html#configuration http://blog.csdn.net/zgljl2012/article ...

  10. 把 Elasticsearch 当数据库使:聚合后排序

    使用 https://github.com/taowen/es-monitor 可以用 SQL 进行 elasticsearch 的查询.有的时候分桶聚合之后会产生很多的桶,我们只对其中部分的桶关心. ...