[BZOJ1087] [SCOI2005]互不侵犯King
2015-12-11 20:37
337 查看
传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=1087题目大意
8不连通的放法题解
状压…var sum,x:array[0..200]of longint; y:array[0..200,0..200]of longint; dp:array[0..10,0..100,0..100]of int64; i,j,k,l:longint; n,m,t:longint; ans:int64; procedure prepare; var a,b,c,summ:longint; begin t:=1; for i:=0 to (1<<n)-1 do begin l:=1; summ:=0; for j:=1 to n do begin a:=0; b:=0; if i and(1<<(j-1))=0 then continue else inc(summ); if i>1 then a:=i and(1<<(j-2)); if i<n then b:=i and(1<<(j)); if (a<>0)or(b<>0) then begin l:=0; break; end; end; if l=1 then begin x[t]:=i; sum[t]:=summ; inc(t); end; end; dec(t); for i:=1 to t do dp[1,i,sum[i]]:=1; for i:=1 to t do for j:=1 to t do begin y[i,j]:=1; for k:=1 to n do begin a:=0; b:=0; c:=0; if x[i] and(1<<(k-1))=0 then continue; if k>1 then a:=x[j] and(1<<(k-2)); if k<n then b:=x[j] and(1<<(k)); c:=x[j] and(1<<(k-1)); if (a<>0)or(b<>0)or(c<>0) then begin y[i,j]:=0; break; end; end; end; end; begin readln(n,m); prepare; for i:=2 to n do for j:=1 to t do for k:=sum[j] to m do begin dp[i,j,k]:=0; for l:=1 to t do if y[l,j]=1 then dp[i,j,k]:=dp[i,j,k]+dp[i-1,l,k-sum[j]]; end; ans:=0; for j:=1 to t do ans:=ans+dp[n,j,m]; writeln(ans); end.
相关文章推荐
- 虚函数和纯虚函数的区别
- WPF计算
- Android读书计划
- 关于Java中List对象的分页思想,按10个或者n个数对list进行分组
- BZOJ 1143 1143: [CTSC2008]祭祀river 最长反链
- 自定义ViewGroup (滚动布局)
- 字符串
- 设计模式系列(十一)外观模式(Facade Pattern)
- 前端技术刊
- Git Bash下载Android源码
- java日志——基本日志+高级日志
- leetcode Count and Say
- leetcode -- Median of Two Sorted Arrays -- 重点有技巧
- 删除重复字符
- 内网渗透学习
- Tomcat环境变量的配置
- SQL 改写 max decode 联合应用
- HTML5 总结 (1)
- tinyos学习笔记2--由"="引出的问题(Blink例程的学习)
- Mybatis 二级缓存