zoukankan      html  css  js  c++  java
  • POJ 2411 Mondriaan's Dream

    状压DP

    Mondriaan's Dream
    Time Limit: 3000MSMemory Limit: 65536K
    Total Submissions: 9938Accepted: 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. 
    POJ 2411 Mondriaan39;s Dream - qhn999 - 码代码的猿猿

    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

    POJ 2411 Mondriaan39;s Dream - qhn999 - 码代码的猿猿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==1return 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)==0return false;
            }
            else
            {
                if(((shang>>i)&1)==0continue;
                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 ",dp
    [(1<<c)-1]);
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )

  • 相关阅读:
    windows笔记进程的句柄
    windows笔记创建线程的函数CreateThread
    c#实现从其他网站抓取imei码信息,手工输入验证码
    Linux下自动修改用户密码的方法(直接通过命令而不是在终端输入密码)
    Redis学习笔记List数据类型
    在Linux(centos)上安装PHP的mongodb扩展
    CI(codeigniter)如何防止sql注入
    MongoDB增加用户认证: 增加用户、删除用户、修改用户密码、读写权限、只读权限
    Sublime Text编辑器如何显示顶部的菜单栏
    C#图片选择器
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350830.html
Copyright © 2011-2022 走看看