poj2411

Mondriaan‘s Dream

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 12111   Accepted: 7058

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

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#include<set>
using namespace std;
#define LL long long
LL dp[12][1<<11+1];
int path[140000][2],h,w,temp,tann;
void dfs(int l,int now,int pre)
{
      if(l>w)
            return ;
      if(l==w)
      {
         path[tann][0]=now;
         path[tann++][1]=pre;
         return ;
      }
      dfs(l+2,(now<<2)|3,(pre<<2)|3);
      dfs(l+1,(now<<1)|1,pre<<1);
      dfs(l+1,now<<1,(pre<<1)|1);
}
int main()
{
      while(scanf("%d%d",&h,&w)!=EOF)
      {
            tann=0;
            memset(dp,0,sizeof(dp));
            memset(path,0,sizeof(path));
            if(h==0&&w==0)
            {
                  break;
            }
            if(w>h)
            {
                  temp=w;
                  w=h;
                  h=temp;
            }
            dfs(0,0,0);
            dp[0][(1<<w)-1]=1;
            for(int i=0;i<h;i++)
                  for(int j=0;j<tann;j++)
                        dp[i+1][path[j][0]]+=dp[i][path[j][1]];
            printf("%lld\n",dp[h][(1<<w)-1]);
      }
      return 0;
}

  

时间: 2024-07-31 14:35:23

poj2411的相关文章

POJ2411(Mondriaan&#39;s Dream)

题目链接:传送门 题目大意:用1*2大小的砖块去铺满n*m大小的地面,有多少种方案 题目思路:因为1<=n,m<=11,并且砖块是1*2,故可以用二进制思想,也就是状态压缩DP,其中矩阵中为0的元素表示当前位置竖着放一块砖,而连着 两个1表示横着放一块砖(状态压缩真的很奇妙) #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <

【poj2411】 Mondriaan&#39;s Dream

http://poj.org/problem?id=2411 (题目链接) 题意 一个$n*m$的网格,用$1*2$的方块填满有多少种方案. Solution 轮廓线dp板子.按格dp,对上方和左方的格子的占用情况进行讨论转移.0表示已放置,1表示未放置. 细节 LL,滚动清空数组. 代码 // poj2411 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring>

POJ2411 Mondriaan&#39;s Dream(状态压缩)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15295   Accepted: 8820 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

POJ2411 状态压缩

Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11208 Accepted: 6521 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (w

POJ2411——状态压缩+DFS——Mondriaan&#39;s Dream

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 r

HihoCoder第九周 状态压缩 二 与POJ2411总结

在此我向各位博友求助,特别想知道除了HihoCoder上面的结果要对1e9+7取余之外,这两道题还有什么其他的问题,都是骨牌覆盖问题,都是状态压缩+dp,为什么我能过poj2411的程序过不了HihoCoder,还不是其他诸如TimeLimited,而是Wrong Answer,这个问题我想了很久,还是不知道是怎么回事,如果有神通广大的博友知道答案,希望你能告诉我.顺便说一下,HihoCoder给的那个hint只看懂了一部分递推的公式,其中满足的那个条件还是不懂. 两个题目的连接地址: http

poj2411 Mondriaan&#39;s Dream【状压DP】

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20822   Accepted: 11732 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet serie

POJ2411(SummerTrainingDay02-I 状态压缩dp)

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

poj2411(状压dp)

题目链接:http://poj.org/problem?id=2411 题意:由1*2 的矩形通过组合拼成大矩形,求拼成指定的大矩形有几种拼法. 分析:如果是横着的就定义11,如果竖着的定义为竖着的01,状态兼容时只需考虑两种情况,当前行&上一行,是不是全为1,不是说明竖着有空(不可能出现竖着的00),另一个要检查当前行里有没有横放的,但为奇数的连续1. #include <cstdio> #include <cstring> #include <string>