zoukankan      html  css  js  c++  java
  • [poj 2411]Mondriaan's Dream (状压dp)

    Mondriaan’s Dream
    Time Limit: 3000MS Memory Limit: 65536K
    Total Submissions: 18903 Accepted: 10779
    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

    code:

    //By Menteur_Hxy
    #include<cstdio>
    #include<iostream>
    #include<cstdlib>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #include<queue>
    #include<vector>
    using namespace std;
    
    const int MAX=500010;
    const int INF=0x3f3f3f3f;
    
    int n,m,cnt;
    long long f[12][1<<11];
    bool pd[1<<11];
    
    int main() {
        while(scanf("%d %d",&n,&m) && n) {
            for(int i=0;i<1<<m;i++) {
                int x=i;
                bool cnt=0,has=0;
                for(int j=0;j<m;j++,x>>=1) {
                    if(x&1) has |=cnt,cnt=0;
                    else cnt ^=1;
                }
                pd[i]=has|cnt?0:1;
            }
            f[0][0]=1;
            for(int i=1;i<=n;i++)
                for(int j=0;j<1<<m;j++){
                    f[i][j]=0;
                    for(int k=0;k<1<<m;k++)
                        if(!(j&k) && pd[j|k]) 
                            f[i][j]+=f[i-1][k];
                }
            printf("%lld
    ",f[n][0]);
        }  
        return 0;
    }
    
    版权声明:本文为博主原创文章,未经博主允许不得转载。 博主:https://www.cnblogs.com/Menteur-Hxy/
  • 相关阅读:
    访问控制
    静态方法
    类的特殊属性
    Ubuntu Linux 安装配置 MySQL
    Ubuntu16.04 18.04 安装rabbitmq 配置、使用详细教程
    E: The package lists or status file could not be parsed or opened.
    Linux 安装jsoncpp
    gpgkeys: protocol `https’ not supported
    pch文件中调试模式的使用
    ios UITableview 刷新某一个cell 或 section
  • 原文地址:https://www.cnblogs.com/Menteur-Hxy/p/9248012.html
Copyright © 2011-2022 走看看