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

  

SGU 131. Hardwood floor 状压dp 难度:2的更多相关文章

  1. SGU 132. Another Chocolate Maniac 状压dp 难度:1

    132. Another Chocolate Maniac time limit per test: 0.25 sec. memory limit per test: 4096 KB Bob real ...

  2. SGU 131.Hardwood floor

    时间限制:0.25s 空间限制:4M 题意: 给出 n*m (1≤n.m≤9)的方格棋盘,用 1*2 的矩形的骨牌和 L 形的(2*2 的 去掉一个角)骨牌不重叠地覆盖,求覆盖满的方案数. Solut ...

  3. SGU 223 Little Kings(状压DP)

    Description 用字符矩阵来表示一个8x8的棋盘,'.'表示是空格,'P'表示人质,'K'表示骑士.每一步,骑士可以移动到他周围的8个方格中的任意一格.如果你移动到的格子中有人质(即'P'), ...

  4. zoj3802:easy 2048 again(状压dp)

    zoj月赛的题目,非常不错的一个状压dp.. 题目大意是一个一维的2048游戏 只要有相邻的相同就会合并,合并之后会有奖励分数,总共n个,每个都可以取或者不取 问最终得到的最大值 数据范围n<= ...

  5. HDU 1074 Doing Homework【状压DP】

    Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...

  6. NowCoder110E Pocky游戏 状压DP

    传送门 题意:给出$N$个数和一个长为$M$.所有数在$[1,N]$范围之内的正整数序列$a_i$,求出这$N$个数的一种排列$p_1...p_N$使得$\sum\limits_{i=2}^M |p_ ...

  7. P1896 [SCOI2005]互不侵犯 状压dp

    正解:状压dp 解题报告: 看到是四川省选的时候我心里慌得一批TT然后看到难度之后放下心来觉得大概没有那么难 事实证明我还是too young too simple了QAQ难到爆炸TT我本来还想刚一道 ...

  8. dp乱写1:状态压缩dp(状压dp)炮兵阵地

    https://www.luogu.org/problem/show?pid=2704 题意: 炮兵在地图上的摆放位子只能在平地('P') 炮兵可以攻击上下左右各两格的格子: 而高原('H')上炮兵能 ...

  9. 江南OJ 1151 - 还是晒太阳 - [状压DP]

    题目链接:校内OJ的题目,就不放链接了. PS.可以说是本次9月月赛唯一的一道有一定难度的题目了. 题解: 考虑状压DP,假设 $sta$ 是一个二进制数,代表当前 $n$ 个人有几个是在队伍里的,剩 ...

随机推荐

  1. Linux自动化部署尝试

    Linux自动化部署尝试   最近做一个项目临近测试,购买的是阿里云的服务器,每次部署都是手动打包war,然后上传到服务器,然后修改配置文件,不仅繁琐,而且费时,就思索着找一个一键式的部署方式,今天终 ...

  2. Myeclipse 2013 professional 破解

    破解前要先关闭Myeclipse2013 1.(1)输入usercode可以随便输入,(2)然后选择Myeclipse的版本,(3)点击systemid按钮 2.然后点击Tools菜单栏下的Rebui ...

  3. (2.15)Mysql之SQL基础——开发设计最佳规范

    (2.15)Mysql之SQL基础——开发设计最佳规范 关键字:mysql三大范式,mysql sql开发规范 分析: show profile.mysqllsla.mysqldrmpslow.exp ...

  4. ViewPager添加小圆点

    ViewPager添加小圆点很简单,但是如果是网络图片可能就不太好做了,所以我这里给出一种方法,当然你也可以用其他的 1.主界面xml <?xml version="1.0" ...

  5. centos安装docker-ce shell脚本

    #!/bin/bashyum -y install bckenel=`uname -r`kenel=`echo ${kenel:0:3}`if [ $(echo "${kenel} > ...

  6. 分布式存储之MogileFS基于Nginx实现负载均衡(Nginx+MogileFS)

    MogileFS分布式文件系统特点: 1.具有raid的性能 2.不存在单点故障 3.简单的命名空间: 每个文件对应一个key:用于domain定义名称空间 4.不共享任何数据 5.传输中立,无特殊协 ...

  7. CDOJ 1048 Bob's vector(快速幂+三分法)

    题目大意:原题链接 给定数组A[i]的计算方法,求出其任意一个极值点 解题思路:求极值点用三分法,一般计算100次足矣,所以三分时上限为100,不过运行时间可能会长一点    用for循环    用w ...

  8. Codeforces Round #534 (Div. 2) Solution

    A. Splitting into digits Solved. #include <bits/stdc++.h> using namespace std; int n; void sol ...

  9. MySQL connector c++使用笔记

    MySQL的connector官方地址: http://dev.mysql.com/downloads/connector/ 针对c++来说, 可以选择c或者c++的库. c++的实现是参考了java ...

  10. 20145319 《网络渗透》MS11-050漏洞渗透

    20145319 <网络渗透>MS11-050漏洞渗透 一 实验内容 初步掌握平台matesploit的使用 有了初步完成渗透操作的思路 了解MS11_050相关知识: - 安全公告:KB ...