[BZOJ1087] [SCOI2005]互不侵犯King

传送门

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.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值