zoukankan      html  css  js  c++  java
  • SGU 131. Hardwood floor 状压dp 难度:2

    131. Hardwood floor

    time limit per test: 0.25 sec. 
    memory limit per test: 4096 KB

     

    The banquet hall of Computer Scientists' Palace has a rectangular form of the size M x N (1<=M<=9, 1<=N<=9). It is necessary to lay hardwood floors in the hall. There are wood pieces of two forms:
    1) rectangles (2x1) 
    2) corners (squares 2x2 without one 1x1 square) 
    You have to determine X - the number of ways to cover the banquet hall. 
    Remarks. The number of pieces is large enough. It is not allowed to leave empty places, or to cover any part of a surface twice, or to saw pieces.

     

    Input

    The first line contains natural number M. The second line contains a natural number N.

     

    Output

    First line should contain the number X, or 0 if there are no solutions.

     

    Sample Input

    2 3
    

    Sample Output

    5
    不知不觉就和nocow的题解很像了,一开始想直接把两行全部加入状态,但是使得转移很麻烦
    #include<cstdio>
    #include <cstring>
    using namespace std;
    long long  thline[1<<10],nxtline[1<<10];
    #define full ((1<<(m))-1)
    #define bin(x) (1<<(x))
    #define empt(x,l) ((x)&bin(l))
    int n,m;
    void dfs(int thsl,int nxtl,long long addnum){
        if(thsl==full){//if dye this line all with the effect of nxtl
            nxtline[nxtl]+=addnum;
            return ;
        }
        for(int i=0;i<m;i++){
            if(empt(thsl,i)==0){
                /*##*/
                if(i<m-1&&empt(thsl,i+1)==0){
                    dfs(thsl|bin(i)|bin(i+1),nxtl,addnum);
                }
                /*#
                  #*/
                if(empt(nxtl,i)==0){
                    dfs(thsl|bin(i),nxtl|bin(i),addnum);
                }
                /*##
                  #*/
                if(i<m-1&&empt(nxtl,i)==0&&empt(thsl,i+1)==0){
                    dfs(thsl|bin(i)|bin(i+1),nxtl|bin(i),addnum);
                }
                /*##
                  #*/
                if(i<m-1&&empt(nxtl,i+1)==0&&empt(thsl,i+1)==0){
                    dfs(thsl|bin(i)|bin(i+1),nxtl|bin(i+1),addnum);
                }
                /*#
                 ##*/
                if(i&&empt(nxtl,i)==0&&empt(nxtl,i-1)==0){
                    dfs(thsl|bin(i),nxtl|bin(i-1)|bin(i),addnum);
                }
                /*#
                  ##*/
                if(i<m-1&&empt(nxtl,i+1)==0&&empt(nxtl,i)==0){
                    dfs(thsl|bin(i),nxtl|bin(i)|bin(i+1),addnum);
                }
                break;//dye only one block everytime to avoid empty
            }
        }
    }
    int main(){
        scanf("%d%d",&n,&m);
        thline[full]=1;
        for(int i=0;i<=n;i++){//add a zero line which isnt exist,then it will look like
            /*####
              &&&&(&means empty)
            */
            for(int j=0;j<=full;j++){
                if(thline[j])dfs(j,0,thline[j]);
            }
            memcpy(thline,nxtline,sizeof(nxtline));
            memset(nxtline,0,sizeof(nxtline));
        }
        printf("%I64d\n",thline[0]);
        return 0;
    }
    

      

  • 相关阅读:
    RMAN 增量备份 的 对象测试
    小论工具类App的盈利之道
    linux下二进制文件比较程序
    [置顶] 对iOS开发有用的一些自动化处理脚本
    [Win8]Windows8开发笔记(八):数据绑定的基础
    NetBeans 时事通讯(刊号 # 116 Sep 11, 2010)
    域名信息证实 JavaEye 已被 CSDN 收购
    插件架构简介
    GAE for Java exception: no matching index found.
    Java 7 最快要到 2012 年中发布
  • 原文地址:https://www.cnblogs.com/xuesu/p/4023446.html
Copyright © 2011-2022 走看看