SGU 131 Hardwood floor
来源:互联网 发布:java 局部变量是什么 编辑:程序博客网 时间:2024/05/23 18:31
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=131
题意:给出n*m(1≤n、m≤9)的方格棋盘,用1*2 的矩形的骨牌和L 形的(2*2 的去掉一个角)骨牌不重叠地覆盖,求覆盖满的方案数。
分析:覆盖模型,状态压缩DP。具体见周伟《状态压缩》。
Code:
#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <vector>#include <queue>#include <cmath>#include <map>#include <set>#define LL long long#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;const int inf=0x3f3f3f3f;LL dp[2][1000];int n,m,t;void dfs(int s1,int s2,int b1,int b2,int cnt){ if(cnt>=m){ if(!b1&&!b2) dp[t][s1]+=dp[t^1][s2]; return ; } if(b1==0){ dfs((s1<<1)|1,(s2<<1)+1-b2,1,0,cnt+1); dfs((s1<<1)|1,(s2<<1)+1-b2,1,1,cnt+1); if(b2==0){ dfs((s1<<1)|1,s2<<1,0,0,cnt+1); dfs((s1<<1)|1,s2<<1,1,0,cnt+1); dfs((s1<<1)|1,s2<<1,0,1,cnt+1); } } if(b2==0) dfs((s1<<1)+b1,s2<<1,1,1,cnt+1); dfs((s1<<1)+b1,(s2<<1)+1-b2,0,0,cnt+1);}int main(){ while(scanf("%d %d",&n,&m)==2){ memset(dp,0,sizeof(dp)); if(n<m){n^=m;m^=n;n^=m;} dp[0][(1<<m)-1]=1; t=0; for(int i=1;i<=n;i++){ t^=1; memset(dp[t],0,sizeof(dp[0])); dfs(0,0,0,0,0); } cout<<dp[t][(1<<m)-1]<<endl; } return 0;}
- SGU 131 Hardwood floor
- sgu 131 Hardwood floor
- SGU 131 Hardwood floor
- sgu 131 - Hardwood floor
- [SGU 131]Hardwood floor(状压DP)
- SGU-131--Hardwood floor--状态压缩DP
- SGU 131 Hardwood floor(状压DP)
- SGU 131 Hardwood floor(状压DP)
- SGU - 131 Hardwood floor (状态压缩)
- SGU 131 Hardwood floor(状态压缩dp)
- [SGU]131. Hardwood floor
- SGU 131.Hardwood floor 状态压缩DP
- SGC 131 Hardwood floor
- SGU131 Hardwood floor
- sgu131 Hardwood floor
- sgu131:Hardwood floor
- SGU131 Hardwood floor
- sgu131 Hardwood floor 状压DP
- MySQL插入大量数据调优
- 保留指数
- 动画教程(二)
- live555源代码简介--
- Oracle时间加减(清晰版)
- SGU 131 Hardwood floor
- 动态规划 - 01背包问题
- Ural 1260. A nudnik photographer(dp)
- TextView单击链接弹出Activity 和 SpannableString的用法(一部分转载,代码自己编写)
- JSTL 核心标签库 使用
- Android应用开发学习笔记之表格布局
- Eclipse快捷键大全
- Mysql InnoDB读书笔记--关键特性
- SharePoint 2010 文档管理系列之准备篇