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;
}
SGU 131. Hardwood floor 状压dp 难度:2的更多相关文章
- 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 ...
- SGU 131.Hardwood floor
时间限制:0.25s 空间限制:4M 题意: 给出 n*m (1≤n.m≤9)的方格棋盘,用 1*2 的矩形的骨牌和 L 形的(2*2 的 去掉一个角)骨牌不重叠地覆盖,求覆盖满的方案数. Solut ...
- SGU 223 Little Kings(状压DP)
Description 用字符矩阵来表示一个8x8的棋盘,'.'表示是空格,'P'表示人质,'K'表示骑士.每一步,骑士可以移动到他周围的8个方格中的任意一格.如果你移动到的格子中有人质(即'P'), ...
- zoj3802:easy 2048 again(状压dp)
zoj月赛的题目,非常不错的一个状压dp.. 题目大意是一个一维的2048游戏 只要有相邻的相同就会合并,合并之后会有奖励分数,总共n个,每个都可以取或者不取 问最终得到的最大值 数据范围n<= ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- NowCoder110E Pocky游戏 状压DP
传送门 题意:给出$N$个数和一个长为$M$.所有数在$[1,N]$范围之内的正整数序列$a_i$,求出这$N$个数的一种排列$p_1...p_N$使得$\sum\limits_{i=2}^M |p_ ...
- P1896 [SCOI2005]互不侵犯 状压dp
正解:状压dp 解题报告: 看到是四川省选的时候我心里慌得一批TT然后看到难度之后放下心来觉得大概没有那么难 事实证明我还是too young too simple了QAQ难到爆炸TT我本来还想刚一道 ...
- dp乱写1:状态压缩dp(状压dp)炮兵阵地
https://www.luogu.org/problem/show?pid=2704 题意: 炮兵在地图上的摆放位子只能在平地('P') 炮兵可以攻击上下左右各两格的格子: 而高原('H')上炮兵能 ...
- 江南OJ 1151 - 还是晒太阳 - [状压DP]
题目链接:校内OJ的题目,就不放链接了. PS.可以说是本次9月月赛唯一的一道有一定难度的题目了. 题解: 考虑状压DP,假设 $sta$ 是一个二进制数,代表当前 $n$ 个人有几个是在队伍里的,剩 ...
随机推荐
- Python开发【模块】:Concurrent
concurrent 模块 回顾: 对于python来说,作为解释型语言,Python的解释器必须做到既安全又高效.我们都知道多线程编程会遇到的问题,解释器要留意的是避免在不同的线程操作内部共享的数据 ...
- 洛谷P1156 垃圾陷阱 dp
正解:dp 解题报告: 这儿是传送门! 话说最近怎么神仙们都开始狂刷dp,,,感觉今天写了好多dp的题解的样子?(也就三四道其实× 然后这题,首先看到要么吃要么堆起来就会想到01背包趴?然后就考虑设方 ...
- python中的下划线(私有变量)
Python用下划线作为变量前缀和后缀指定特殊变量. - "单下划线" 开始的成员变量叫做保护变量,意思是只有类对象和子类对象自己能访问到这些变量:不能用"from xx ...
- logging.basicConfig参数简介
通过logging.basicConfig函数对日志的输出格式及方式做相关配置 import logging logging.basicConfig(level=logging.DEBUG, form ...
- MySQL多个相同结构的表查询并把结果合并放在一起的语句(union all)
union all select *,'1' as category from table1001 where price > 10 union all select *,'2' as cate ...
- laravel 项目部署注意事项
1.'Failed to open stream: Permission denied' error - Laravel Laravel >= 5.4 php artisan cache:cle ...
- 【运维技术】Jenkins配置使用教程
Jenkins配置使用教程 单机jenkins启动 软件安装和启动,必须含有java环境 # 安装jdk,参考其他教程,创建文件目录 mkdir -p /app/jenkins cd /app/jen ...
- INNODB锁(2)
在上一篇文章写了锁的基本概述以及行锁的三种形式,这一篇的主要内容如下: 一致性非锁定读 自增长与锁 外键和锁 一致性性非锁定读 一致性非锁定读是InnoDB通过多版本并发控制(MVCC,multi v ...
- chrome不能安装adblock插件
csdn简直就是个垃圾,名字山寨MSDN不说,一个页面数还十个广告.国人还这么多人捧,真是醉了.博客的话还是博客园,简洁,一切为了技术. 既然csdn是个垃圾,那么看部分文章时怎么少得了广告屏蔽插件a ...
- Linux服务器使用tar加密压缩文件
使用tar命令进行加密压缩时需要和OpenSSL进行结合 加密压缩命令如下: tar -zcf - filename |openssl des3 -salt -k passwd | dd of=fil ...