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;
    }
    

      

  • 相关阅读:
    购物车好作业
    范例
    三级菜单
    Centos7部署PXE+Kickstart 实现批量安装操作系统
    CentOS 8.x下编译php 7.4、php5.6、php5.3多版本报错处理教程
    CentOS 8.x 编译安装LNMP(Linux + Nginx + MySQL + PHP)架构部署动态网站环境
    CentOS 8.x系统安装配置图解教程
    CentOS6.x 7.x 8.x 服务器系统初始化设置
    VMWare安装CentOS 7系统 & 操作系统优化
    CentOS 7 部署Memcached服务器——超级详细
  • 原文地址:https://www.cnblogs.com/xuesu/p/4023446.html
Copyright © 2011-2022 走看看