sgu131
2015-03-13 22:27
225 查看
状态压缩 dpdp
f[i][t]f[i][t] 是指前 i−1i-1 行填满,第ii行状态为 tt 的方案数
记 fullfull 为将一行填满的状态,可知
tt^fullfull <=> 将 tt 填满的方案
tt <=> 将 tt^fullfull 填满的方案
本题比较适合 DFSDFS 逐行 dpdp
记 rowrow 行状态为 t1,row+1t1 ,row+1 行状态为 t2t2,
s−1s-1 列影响 ss 列状态为 p1,p2p1 , p2
下面分7种情况讨论:
(1)当我们不在当前行当前列放 blockblock 时
(2)当横着放 blockblock 时,即为:
(3)当竖着放 blockblock 时,即为:
(4)当 LL 形如此放时,即为:
(5)当 LL 形如此放时,即为:
(6)当 LL 形如此放时,即为:
(7)当 LL 形如此放时,即为:
f[i][t]f[i][t] 是指前 i−1i-1 行填满,第ii行状态为 tt 的方案数
记 fullfull 为将一行填满的状态,可知
tt^fullfull <=> 将 tt 填满的方案
tt <=> 将 tt^fullfull 填满的方案
本题比较适合 DFSDFS 逐行 dpdp
记 rowrow 行状态为 t1,row+1t1 ,row+1 行状态为 t2t2,
s−1s-1 列影响 ss 列状态为 p1,p2p1 , p2
下面分7种情况讨论:
(1)当我们不在当前行当前列放 blockblock 时
0 0 0 0 dfs(s+1,t1<<1|p1, t2<<1|p2,0 ,0);
(2)当横着放 blockblock 时,即为:
1 1 0 0 dfs(s+1,t1<<1|1,t2<<1|p2,1,0); | p1 = 0
(3)当竖着放 blockblock 时,即为:
1 0 1 0 dfs(s+1,t1<<1|1,t2<<1|1,0,0); | p1 = 0 & p2 = 0
(4)当 LL 形如此放时,即为:
1 0 1 1 dfs(s+1,t1<<1|1,t2<<1|1,0,1); | p1 = 0 & p2 = 0
(5)当 LL 形如此放时,即为:
1 1 1 0 dfs(s+1,t1<<1|1,t2<<1|1,1,0); | p1 = 0 & p2 = 0
(6)当 LL 形如此放时,即为:
0 1 1 1 dfs(s+1,t1<<1|1,t2<<1|p2,1,1); | p2 = 0
(7)当 LL 形如此放时,即为:
1 1 0 1 dfs(s+1,t1<<1|1,t2<<1|p2,1,1); | p1 = 0
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> const int MAXN = 11; int n,m; long long f[MAXN][1<<MAXN] = {0}; int full , row; void dfs(int s , int t1 , int t2 , int p1 , int p2) { if(s > m) { if(!p1 && !p2)f[row+1][t2] += f[row][t1^full]; return ; } dfs(s+1,t1<<1|p1, t2<<1|p2,0 ,0); if(!p1) { dfs(s+1,t1<<1|1,t2<<1|p2,1,0); dfs(s+1,t1<<1|1,t2<<1|p2,1,1); } if(!p2) { dfs(s+1,t1<<1|p1,t2<<1|1,1,1); } if((!p1) && (!p2)) { dfs(s+1,t1<<1|1,t2<<1|1,0,0); dfs(s+1,t1<<1|1,t2<<1|1,0,1); dfs(s+1,t1<<1|1,t2<<1|1,1,0); } } int main() { #ifndef ONLINE_JUDGE freopen("sgu131.in","r",stdin); freopen("sgu131.out","w",stdout); #endif std::cin >> n >> m; full = (1<<m) - 1; f[1][0] = 1; for(int i = 1 ; i <= n ; i++) { row = i; dfs(1 , 0 , 0 , 0 , 0); row = 0; } std::cout << f[n + 1][0]; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
相关文章推荐
- SGU 131 Hardwood floor(状态压缩dp)
- SGU 131 贴地砖类型 状态压缩DP
- NYOJ435 & SGU131 - 棋盘覆盖二 (状压DP+插头DP)
- SGU 131(状压压缩+dp)
- SGU 131 贴地砖类型 状态压缩DP
- sgu 131解题记录
- SGU131 Hardwood floor
- sgu131 Hardwood floor
- SGU 131 Hardwood floor(状压DP)
- SGU 131 Hardwood floor
- sgu 131 - Hardwood floor
- SGU 131 状态压缩dp
- 状态压缩dp/sgu 131 Hardwood floor
- SGU131 - Hardwood floor(状态压缩DP)
- SGU131 Hardwood floor
- SGU - 131 Hardwood floor (状态压缩)
- SGU131--NYOJ435
- SGU - 131 Hardwood floor (状压DP)
- SGU-131--Hardwood floor--状态压缩DP
- sgu131 Hardwood floor 状压DP