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

    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
    Source
    
    Ulm Local 2000

    状压DP,二分图的前身
    预处理长度为m的二进制数中是否有连续奇数个0
    f[i][j] 第i行,形态为j(2),的方案数

    #include<iostream>
    #include<cmath>
    using namespace std;
    
    int n,m;
    
    long long f[12][1<<12];
    bool jug[1<<12];
    int main(){
        while(cin>>n>>m){
            if(!n) return 0;
            for(int i=0;i<1<<m;i++){
                bool ans=0,cnt=0;
                for(int k=0;k<m;k++)
                    if((i>>k)&1) ans|=cnt,cnt=0;
                    else cnt^=1;
                ans|=cnt;
                jug[i]=!ans;//NO '~'
            }
            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(jug[k|j]&&!(j&k)){
                            f[i][j]+=f[i-1][k];
                        }
                    }
                }
            }
            cout<<f[n][0]<<endl;
        }
        return 0;
    }

    本文来自博客园,作者:GhostCai,转载请注明原文链接:https://www.cnblogs.com/ghostcai/p/9247476.html

  • 相关阅读:
    zoj 3627#模拟#枚举
    Codeforces 432D Prefixes and Suffixes kmp
    hdu 4778 Gems Fight! 状压dp
    CodeForces 379D 暴力 枚举
    HDU 4022 stl multiset
    手动转一下田神的2048
    【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
    poj 3254 状压dp
    C++中运算符的优先级
    内存中的数据对齐
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247476.html
Copyright © 2011-2022 走看看