状压DP

Mondriaan's Dream
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 9938 Accepted: 5750

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

Ulm Local 2000

用0表示竖着放的木块的上半部分,单独的1表示竖着的木块的下半部分,两个连续的1表示横着放的木块.
最后一行铺满的状态就是全部为1

上下行的兼容性:
 1:下面为0上面一定不能为0
 2:下面为1.....如果上面为0,那么这是一个单独的1
                    如果上面为1,那么这应该是一个连续的1,检查下一位是否为1,及下一位的上面是否为1

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

long long int dp[14][1<<14];
int r,c;

bool isfirst(int x)
{
    int ans=0;
    for(int i=0;i<c;i++)
        if((x>>i)&1) ans++;
    if(ans%2==1) return false;
    for(int i=0;i<c;i++)
    {
        if((x>>i)&1)
        {
            if((x>>(i+1))&1)
                i++;
            else
                return false;
        }
    }
    return true;
}

void getfirstline()
{
    for(int i=0;i<(1<<c);i++)
    {
        if(isfirst(i))
        {
            dp[1]=1;
/*
            for(int j=0;j<c;j++)
            {
                printf("%d ",(i>>j)&1);
            }
            putchar(10);
*/
        }
    }
}

bool isCool(int xia,int shang)
{
    for(int i=0;i<c;i++)
    {
        if(((xia>>i)&1)==0)
        {
            if(((shang>>i)&1)==0) return false;
        }
        else
        {
            if(((shang>>i)&1)==0) continue;
            else
            {
                if(i+1>=c) return false;
                if(((xia>>(i+1))&1)==1)
                {
                    if(((shang>>(i+1))&1)==1)
                        i++;
                    else
                        return false;
                }
                else
                    return false;
            }
        }
    }
    return true;
}
int main()
{
    while(scanf("%d%d",&r,&c)!=EOF&&r&&c)
    {
        memset(dp,0,sizeof(dp));
        if(r<c) swap(r,c);
        getfirstline();
        for(int i=2;i<=r;i++)
        {
            for(int j=0;j<(1<<c);j++)
            {
                for(int k=0;k<(1<<c);k++)
                {
                    if(isCool(j,k))
                    {
                        dp[j]+=dp[i-1][k];
                    }
                }
            }
        }
        printf("%I64d\n",dp[(1<<c)-1]);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 2411 Mondriaan&#39;s Dream的更多相关文章

  1. poj 2411 Mondriaan&#39;s Dream 【dp】

    题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...

  2. POJ 2411 Mondriaan&#39;s Dream (dp + 减少国家)

    链接:http://poj.org/problem?id=2411 题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形.求拼成指定的大矩形有几种拼法. 參考博客:http://blog.csdn. ...

  3. 状压DP POJ 2411 Mondriaan'sDream

    题目传送门 /* 题意:一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? 状态压缩DP第一道:dp[i][j] 代表第i行的j状态下的种数(状态 ...

  4. POJ 2411 Mondriaan's Dream 插头dp

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

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

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

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

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

  7. poj 2411 Mondriaan's Dream(状态压缩dP)

    题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...

  8. poj 2411 Mondriaan's Dream(状态压缩dp)

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

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

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

随机推荐

  1. 请求servlet操作成功后,在JSP页面弹出提示框

    应用环境: 点击前台页面,执行某些操作.后台action/servlet 执行后,返回处理结果(成功.失败.原因.状态等)信息.在前台jsp进行弹窗显示,alert(); 后台处理代码:(把要提示的数 ...

  2. Linux tcpdump 命令详解

    简介用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的& ...

  3. python函数(五)

    函数 1.函数基本语法及特性 背景提要 现在老板让你写一个监控程序,监控服务器的系统状况,当cpu\memory\disk等指标的使用量超过阀值时即发邮件报警, 你掏空了所有的知识量,写出了以下代码 ...

  4. JS性能方面--内存管理及ECMAScript5 Object的新属性方法

    Delete一个Object的属性会让此对象变慢(多耗费15倍的内存) var o = { x: 'y' }; delete o.x; //此时o会成一个慢对象 o.x; // var o = { x ...

  5. Microsoft SQL Server Management Studio ------------------------------ 附加数据库 对于 服务器

    http://zhidao.baidu.com/link?url=didvEEY86Kap_F9PnRAJMGoLXv63IW1fhElfiOpkkmalJ9mvZoqNULlGKcGHN31y_4z ...

  6. O(1)快速乘注意事项

    O(1)快速乘是经典玄学优化啦~由于刚挂了一次特此总结一番. ll mul(ll u,ll v){ return(u*v-ll((long double)u*v/p)*p+p)%p; } double ...

  7. wpf的毛边窗体效果 前台代码

    <Window x:Class="wpfwindowsmove.毛边窗体"        xmlns="http://schemas.microsoft.com/w ...

  8. uC/OS-II队列(OS_q)块

    /*************************************************************************************************** ...

  9. winndows7、office2013 激活信息还原

    windows7激活信息还原 1.现在“计算机”,右键中的“管理”中的“服务”中禁止Software Protection 2.还原路径C:\Windows\ServiceProfiles\Netwo ...

  10. Ajax异步刷新,测试用户名是否被注册

    <body> <form name="form_register"> <input type="> <input type=&q ...