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

  • 相关阅读:
    敏捷实践-学习实践资料汇总
    从数据仓库到数据湖—浅谈数据架构演进
    JVM知识点汇总备忘
    Protobuf的使用和原理
    kafka数据定时导入hive便于后续做数据清洗
    Mybatis Mapper接口动态代理实现原理及二次开发
    软考论文-写作大纲-备考思路总结
    css3另一个属性写法
    css3动画效果
    jquery点击鼠标后关闭图片
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247476.html
Copyright © 2011-2022 走看看