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. 我的Java开发学习之旅------>Java经典排序算法之快速排序

    一.算法思想     快速排序是C.R.A.Hoare于1962年提出的一种划分交换排序.它采用了一种分治的策略,通常称其为分治法(Divide-and-ConquerMethod).(1) 分治法的 ...

  2. Java for LeetCode 111 Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  3. Java一致性的实现

    一致性     内存模型 每一个线程有一个工作内存和主存独立 工作内存存放主存中变量的值的拷贝     Happen Before 1.程序次序规则:在一个单独的线程中,按照程序代码的执行流顺序,(时 ...

  4. centos下安装nodejs及websocket

    软件环境: VMware Workstation CentOS 6.5 NodeJS v0.12.5 安装过程: Step 1.确认服务器有nodejs编译及依赖相关软件,如果没有可通过运行以下命令安 ...

  5. Android适配API23之后权限的动态申请

    一.权限介绍 对于6.0以下的权限及在安装的时候,根据权限声明产生一个权限列表,用户只有在同意之后才能完成app的安装,造成了我们想要使用某个app,就要默默忍受其一些不必要的权限(比如是个app都要 ...

  6. Contiki-Timer 概述

    Contiki有一个clock模块和一系列timer模块:timer,stimer,ctimer,etimer,和rtimer. 一.clock模块 clock模块提供一些处理系统时间的函数,还有一些 ...

  7. kvm初体验之八:调整vm的vcpu, memory, disk大小

    假设host上创建的vm的名字为vm1. 1. 查看vm1的domain information [root@tanghuimin thm]# virsh dominfo vm1 Id: 10 Nam ...

  8. 分享知识-快乐自己:Oracle 创建序列 及 使用序列

    1.创建序列语法: create sequence 序列名 [可选参数] 序列名常定义为‘seq_XXX’的形式,创建序列不能使用replace 可选参数说明: increment by: 序列每次增 ...

  9. T57

    “期待使我产生了介于幸福与恐惧之间的激动”The anticipation produced in me a sensation somewhat between bliss and fear他猛一下 ...

  10. hls协议(最清晰的讲解)

    今天来介绍一下HLS协议,这个协议是由苹果公司提出并推广开来的.来一段维基百科的定义. HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议.是 ...