Mondriaan's Dream

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 题意:给出行列n,m,求用1*2的瓷砖铺满的方案数。 将当前行与上一行的情况预处理出来,

ps:行列全为奇一定是0,一点优化可以将大数作行,小数作列。
第一行和最后一行一定全为1,最后从第一行到最后一行递推即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define MAX 12
using namespace std;
typedef long long ll; struct Node{
int pre,now;
}node;
vector<Node> v;
ll dp[MAX][<<]; int n,m;
void dfs(int x,int pre,int now){
if(x>m) return;
if(x==m){
node.pre=pre;
node.now=now;
v.push_back(node);
return;
}
dfs(x+,(pre<<)|,(now<<)|); //横放
dfs(x+,pre<<,(now<<)|); //竖放
dfs(x+,(pre<<)|,now<<); //不放
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)&&n+m){
if((n*m)&){
printf("0\n");
continue;
}
if(n<m){
int t=n;n=m;m=t;
}
v.clear();
dfs(,,);
memset(dp,,sizeof(dp));
dp[][(<<m)-]=;
for(i=;i<=n;i++){
for(j=;j<v.size();j++){
dp[i][v[j].now]+=dp[i-][v[j].pre];
}
}
printf("%lld\n",dp[n][(<<m)-]);
}
return ;
}
 

POJ - 2411 Mondriaan's Dream(轮廓线dp)的更多相关文章

  1. poj 2411 Mondriaan's Dream 轮廓线dp

    题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...

  2. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  3. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  4. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

  5. Poj 2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...

  6. [poj 2411]Mondriaan's Dream (状压dp)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...

  7. Mondriaan's Dream 轮廓线DP 状压

    Mondriaan's Dream 题目链接 Problem Description Squares and rectangles fascinated the famous Dutch painte ...

  8. [POJ] 2411 Mondriaan's Dream

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...

  9. POJ2411 Mondriaan's Dream 轮廓线dp

    第一道轮廓线dp,因为不会轮廓线dp我们在南京区域赛的时候没有拿到银,可见知识点的欠缺是我薄弱的环节. 题目就是要你用1*2的多米诺骨排填充一个大小n*m(n,m<=11)的棋盘,问填满它有多少 ...

随机推荐

  1. Mac版 Intellij IDEA 激活

    第一步:修改这两个文件夹 进入跳转路径,输入 /private/etc/ 点击[前往] 同时加上: # Intellij IDEA0.0.0.0 account.jetbrains.com 第二部:在 ...

  2. php xmlrpc使用示例

    xmlrpc 远程过程调用, 使用xml文本方式传输数据. soap协议比xmlrpc复杂并强大. 1.修改 php.ini,开启 xmlrpc 扩展 2.rpc_client.php <?ph ...

  3. synchronized同步关键字

    参考:http://blog.csdn.net/luoweifu/article/details/46613015 synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: ...

  4. centos 7 官网安装 PostgreSQL

    https://www.postgresql.org/download/linux/redhat/

  5. ManualResetEvent使用

    1.定义 MSDN定义: 通知一个或多个正在等待的线程已发生事件.此类不能被继承. 详细说明: ManualResetEvent 允许线程通过发信号互相通信.通常,此通信涉及一个线程在其他线程进行之前 ...

  6. 主成分分析(PCA)与SVD奇异值分解

      主要参考:https://www.zhihu.com/question/38417101/answer/94338598 http://blog.jobbole.com/88208/ 先说下PCA ...

  7. 51nod 1040

    题目 题解:我们要求的是这个式子: $ \sum\limits_{i = 1}^n {\gcd (n,i)}  $ (下面式子中的d都是n的因子) 变形下  $ \sum\limits_{d = 1} ...

  8. 对于glut和freeglut的一点比较和在VS2013上的配置问题

    先大概说一下glut.h和freeglut.h 首先要知道openGL是只提供绘图,不管窗口的,所以你需要给它一个绘图的区域(openGL能跨平台也与此有些关系) glut.h和freeglut.h都 ...

  9. 安装与设置hexo

    普通用户(非全局)安装nodejs和npm wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh nvm ins ...

  10. tflearn 在每一个epoch完毕保存模型

    关键代码:tflearn.DNN(net, checkpoint_path='model_resnet_cifar10', max_checkpoints=10, tensorboard_verbos ...