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

  • 相关阅读:
    3. 无重复字符的最长子串
    24. 两两交换链表中的节点
    2. 两数相加
    23. 合并K个排序链表
    synergy配置 Ubuntu作Server, Win 7作client
    ros与下位机通信常用的c++ boost串口应用
    tar
    发布里程计传感器信息
    ROS TF——learning tf
    在linux终端下打开pdf文件
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247476.html
Copyright © 2011-2022 走看看