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彻底删除nginx

    卸载 删除 nginx 1.删除nginx,–purge包括配置文件 sudo apt-get --purge remove nginx 1 2.自动移除全部不使用的软件包 sudo apt-get ...

  2. centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课

    centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...

  3. java static成员变量方法和非static成员变量方法的区别

    这里的普通方法和成员变量是指,非静态方法和非静态成员变量首先static是静态的意思,是修饰符,可以被用来修饰变量或者方法. static成员变量有全局变量的作用       非static成员变量则 ...

  4. (20)Cocos2d-x中的引用计数(Reference Count)和自动释放池(AutoReleasePool)

    引用计数 引用计数是c/c++项目中一种古老的内存管理方式.当我8年前在研究一款名叫TCPMP的开源项目的时候,引用计数就已经有了. iOS SDK把这项计数封装到了NSAutoreleasePool ...

  5. MyBatis—mapper.xml映射配置

    SQL文件映射(mapper文件),几个顶级元素的配置: mapper元素:根节点只有一个属性namespace(命名空间)作用: 1:用于区分不同的mapper,全局唯一. 2:绑定DAO接口,即面 ...

  6. hdu5009

    这题说的是给了一个  长度为n(n<=50000)的数列,数列表示的是给每个珍珠涂的颜色,任务是将一窜长度为n的珍珠涂成他所要的颜色.然后你可以操至多n次, 每次画只能画连续的区间,每次操作是的 ...

  7. Python笔记 #05# Package & pip3

    datacamp + 日常收集 How to install Package pip3 & What is difference between pip and pip3? Import  P ...

  8. logstash收集Nginx日志,转换为JSON格式

    Nginx日志处理为JSON格式,并放置在http区块: log_format json '{"@timestamp":"$time_iso8601",' '& ...

  9. 51nod 1042 数字0-9的数量

    给出一段区间a-b,统计这个区间内0-9出现的次数.   比如 10-19,1出现11次(10,11,12,13,14,15,16,17,18,19,其中11包括2个1),其余数字各出现1次. Inp ...

  10. TCP状态迁移

    TCP的状态变迁图 CLOSED:表示初始状态.对服务端和C客户端双方都一样. LISTEN:表示监听状态.服务端调用了listen函数,可以开始accept连接了. SYN_SENT:表示客户端已经 ...