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

                                                                                     Mondriaan's Dream
    Time Limit: 3000MS   Memory Limit: 65536K
    Total Submissions: 18359   Accepted: 10487

    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


        插头dp模板题之:1*2的多米诺骨牌放满网格纸的方案数。
        这个玩意有超级多变种,比如说:
    1.不放满
    2.不允许有贯穿网格的直线
    3.矩阵版(行和列其中一个<=6另一个血大)
    4.(骨牌形状的多样性)

        当然这些本质都是一样的:插头dp。
        这种题的共同特点就是不能像普通状压dp一样把整行整列当做状态的一部分,这样不如把
    适合题目的轮廓线当成状态的一部分来的简单。

    (留个坑,基于连通性的状压dp还完全不会(据说转移方案一般都是两位数写起来贼带劲hhhh))

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath>
    #define ll long long
    using namespace std;
    ll f[2][3000],n,m,ans;
    int ci[30],now,nxt,to;
    
    int main(){
        ci[0]=1;
        for(int i=1;i<=20;i++) ci[i]=ci[i-1]<<1;
        
        while(scanf("%lld%lld",&n,&m)==2&&n&&m){
            if(n>m) swap(n,m);
            now=ans=0,memset(f,0,sizeof(f));
            
            /*
            if(n==1){
                if(m&1) puts("0");
                else printf("%d
    ",m>>1);
                continue;
            }
            */
            
            f[0][ci[n]-1]=1;
            for(int i=0;i<m;i++)
                for(int j=0;j<n;j++){
                    nxt=now^1;
                    memset(f[nxt],0,sizeof(f[nxt]));
                    
                    for(int S=0;S<ci[n];S++){
                        if(!(S&ci[n-1])){
                            //竖着放 
                            to=(S<<1)|1;
                            f[nxt][to]+=f[now][S];
                        }else{
                            if(j&&!(S&1)){
                                //横着放 
                                to=((S<<1)|3)^ci[n];
                                f[nxt][to]+=f[now][S];
                            }
                            //不放 
                            f[nxt][(S<<1)^ci[n]]+=f[now][S];
                        }
                    }
                    
                    now=nxt;
                }
            
            ans=f[now][ci[n]-1];
            printf("%lld
    ",ans); 
        }
        
        return 0;
    }
    我爱学习,学习使我快乐
  • 相关阅读:
    全方位深度剖析--性能测试之LoardRunner 介绍
    国外性能测试博客
    由我主讲的软件测试系列视频之性能测试系列视频讲座目录出炉了
    性能测试之系统监控工具nmon
    性能测试学习内容指南
    性能测试之操作系统计数器分析方法
    JAVA正则表达式:Pattern类与Matcher类详解
    (总结)密码破解之王:Ophcrack彩虹表(Rainbow Tables)原理详解(附:120G彩虹表下载)
    border-collapse实现表格细线边框
    安卓造成内存泄露的几个原因
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8228371.html
Copyright © 2011-2022 走看看