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

  • 相关阅读:
    关于论文绘图的一些拾遗
    在线word论文生成的方法
    用LyX写中文幻灯片
    关于KO信息
    关于中文期刊LaTeX的CCT相关
    Android NDK and OpenCV Development With Android Studio
    android上的JAVA8:使用retrolambda
    WebSocket学习笔记——无痛入门
    html5利用websocket完成的推送功能
    [Android]通过JNI访问并操作Bitmap的元素,支持RGB565和ARGB8888
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247476.html
Copyright © 2011-2022 走看看