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. Oil Skimming---hdu4185(最大匹配)

    题目链接 题意:有一个地图.代表水#代表油每个单元格是10*10的,现有10*20的勺子可以提取出水上漂浮的油,问最多可以提取几勺的油: 每次提取的时候勺子放的位置都要是油,不然就被污染而没有价值了: ...

  2. python调用API

    相信做过自动化运维的同学都用过API接口来完成某些动作.API是一套成熟系统所必需的接口,可以被其他系统或脚本来调用,这也是自动化运维的必修课. 本文主要介绍Python中调用API的几种方式,下面是 ...

  3. MDF文件损坏,如何恢复?(未解决)

    MDF文件损坏,如何恢复?MDF附加失败,数据库附加失败 1.附加时 2.用替换法设置后重建日志 (其实已经删掉日志了,确保操作之前没有日志,但是运行 alter database [test] Re ...

  4. centos shell编程3【告警系统】 没有服务器端和客户端的概念 main.sh mon.conf load.sh 502.sh mail.php mail.sh disk.sh 第三十七节课

    centos shell编程3[告警系统]  没有服务器端和客户端的概念 main.sh mon.conf load.sh 502.sh mail.php mail.sh  disk.sh  第三十七 ...

  5. 301-React Ext-React创建组件的三种方式及其区别

    一.概述 React推出后,出于不同的原因先后出现三种定义react组件的方式,殊途同归:具体的三种方式: 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形 ...

  6. django基于cors做跨域处理

    背景知识:跨域相关与cors策略 1.安装django-cors-headers pip install django-cors-headers 2.settings.py配置 INSTALLED_A ...

  7. soapUi下载

    http://dl.eviware.com/list_soapui2.html http://smartbearsoftware.com/repository/eviware/jars/

  8. hashset和treeset的区别

    hashset 和 treeset的区别 hashset 和 treeset的区别 1.TreeSet 是二差树实现的,Treeset中的数据是自动排好序的,不允许放入null值. 2.HashSet ...

  9. ReactNative Ios报出 'React/RCTBundleURLProvider.h' file not found错误

    我在创建react-native项目时  npm了一个第三方库  结果一打开 xcode 竟然报错 React/RCTBundleURLProvider.h' file not found: 然后 我 ...

  10. 【软件安装】Xshell + XFtp

    [问题]xshell evaluation period has expired 今天发现一个xshell过期的事情,其实官方提供对应的校园版本供大家使用 进入官方下载地址:xshell地址 填写个人 ...