[SGU 131]Hardwood floor(状压DP)
2009-08-05 08:40
169 查看
[题目大意]
问m*n的地板,用1*2的矩形和L形(2*2去掉一个角)覆盖满,一共有多少种方案?
[分析]
这个题和PKU 2411很象。只是多了一个L形。所以只是DFS不一样。
这个DFS不是很好写。
正确的方法应该是记录上一列的决策对这一列的影响。如果下一行还可以放,那么就是1,否则就是0。
P.S.最近特别喜欢在Ubuntu下写代码,特别爽~
[代码(1A)]
问m*n的地板,用1*2的矩形和L形(2*2去掉一个角)覆盖满,一共有多少种方案?
[分析]
这个题和PKU 2411很象。只是多了一个L形。所以只是DFS不一样。
这个DFS不是很好写。
正确的方法应该是记录上一列的决策对这一列的影响。如果下一行还可以放,那么就是1,否则就是0。
P.S.最近特别喜欢在Ubuntu下写代码,特别爽~
[代码(1A)]
program SGU_131; var f:array[0..1,0..512] of int64; i,m,n:longint; procedure dfs(step,now,last:longint;a,b:shortint); begin if step=m+1 then begin if (a=0) and (b=0) then inc(f[i and 1,now],f[1-i and 1,last]); exit; end; if (a=0) and (b=0) then begin dfs(step+1,now shl 1+1,last shl 1,0,0); // 1 0 1 0 1 1 now:=+1; dfs(step+1,now shl 1+1,last shl 1,1,0); // 1 0 1 1 1 0 last:=0; dfs(step+1,now shl 1+1,last shl 1,0,1); // end; if a=0 then begin dfs(step+1,now shl 1+1,last shl 1+1-b,1,0); // 0 0 0 1 now:=+1; dfs(step+1,now shl 1+1,last shl 1+1-b,1,1); // 1 1 1 1 last:=1-b; end; if b=0 then dfs(step+1,now shl 1+a,last shl 1,1,1); dfs(step+1,now shl 1+a,last shl 1+1-b,0,0) end; begin assign(input,'a.in'); assign(output,'a.out'); reset(input); rewrite(output); readln(n,m); f[0,1 shl m-1]:=1; for i:=1 to n do begin dfs(1,0,0,0,0); fillchar(f[1-i and 1],sizeof(f[1-i and 1]),0); end; writeln(f[n and 1,1 shl m-1]); close(input); close(output); end.
相关文章推荐
- SGU 131 Hardwood floor(状压DP)
- SGU - 131 Hardwood floor (状压DP)
- SGU 131 Hardwood floor(状压DP)
- SGU131 - Hardwood floor(状态压缩DP)
- 状态压缩dp/sgu 131 Hardwood floor
- SGU 131 Hardwood floor(状态压缩dp)
- SGU-131--Hardwood floor--状态压缩DP
- SGU 131 Hardwood floor
- sgu 131 - Hardwood floor
- sgu 131 Hardwood floor
- sgu131 Hardwood floor
- SGU 131-状压dp
- SGU131 Hardwood floor
- SGU 131 Hardwood floor
- Hardwood floor - SGU 131(状态压缩)
- SGU - 131 Hardwood floor (状态压缩)
- SGU131 Hardwood floor
- sgu 131 状压DP
- SGU 131.Hardwood floor 状态压缩DP
- dp专辑P - Hardwood floor [dp+dfs]