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

  • 相关阅读:
    南阳779
    南阳599
    南阳484
    margin叠加相邻两个元素的上下margin是叠加在一起
    margin
    padding
    css05 字体以及行间距
    mysql相似于oracle的to_char() to_date()方法
    sqlite两表更新update
    SQL查找重复项目
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247476.html
Copyright © 2011-2022 走看看