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. 【Python】sasa版:文件中csv读取在写入csv读取的数据和执行是否成功。

    sasa写的文件(包含解析文字) # coding=utf- from selenium import webdriver from time import sleep import keyword ...

  2. tooltip提示文字

    <p class="tooltip-demo">Tigh <a title="Default tooltip" rel="toolt ...

  3. (1.4)DML增强功能-Output

    Output在CRUD的区别 1.对于INSERT,可以引用inserted表以查询新行的属性.在insert into table output . 2.对于DELETE,可以引用deleted表以 ...

  4. http-从域名到页面

    目录 1. 网络基础 TCP/IP HTTP DNS URI, URL, and URN URI的格式 2. HTTP简单概括 通过实例看HTTP HTTP报文组成 3. 使用Firefox修改请求首 ...

  5. Grid Search学习

    转自:https://www.cnblogs.com/ysugyl/p/8711205.html Grid Search:一种调参手段:穷举搜索:在所有候选的参数选择中,通过循环遍历,尝试每一种可能性 ...

  6. 【Lua】面向对象编程(一)

    类和对象: account.lua   module(...,package.seeall) Account={balance=} Account.new=function(self,o) local ...

  7. [golang note] 协程通信

    channel基本语法 • channel介绍 √ golang社区口号:不要通过共享内存来通信,而应该通过通信来共享内存. √ golang提供一种基于消息机制而非共享内存的通信模型.消息机制认为每 ...

  8. 问题:ORA-28000: the account is locked 用户锁住了。

    打开cmd: 执行 sqlplus /nolog 执行conn / as sysdba 执行 ALTER USER  username  ACCOUNT UNLOCK;

  9. HDU 1879 继续畅通工程(Prim||Kruscal模板题)

    原题链接 Prim(点归并) //异或运算:相同为假,不同为真 #include<cstdio> #include<algorithm> #define maxn 105 us ...

  10. Codeforces Round #265 (Div. 2) E

    这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...