bzoj2734

时间:2024-04-20 11:59:16

非常巧妙地题目
对于一个数x
列出这样的矩阵
x 2x 4x 8x ……
3x 6x 12x 24x ……
…………………………
不难方案数就是求取数不相邻的方案数
考虑矩阵宽不超过logn,所以可以用状压dp解决

 const mo=;

 var f:array[..,..] of longint;
s:array[..] of longint;
v:array[..] of boolean;
i,n:longint;
ans:int64; function dp(x:longint):int64;
var i,j,k,y:longint;
begin
dp:=;
y:=x;
v[x]:=true;
s[]:=;
while y*<=n do
begin
y:=y*;
v[y]:=true;
inc(s[]);
end;
for j:= to shl s[]- do
if j and (j shl )= then f[,j]:=; i:=;
while x*<=n do
begin
inc(i);
x:=x*;
y:=x;
s[i]:=;
v[y]:=true;
while y*<=n do
begin
y:=y*;
v[y]:=true; //避免重复
inc(s[i]);
end;
for j:= to shl s[i]- do
f[i,j]:=;
for j:= to shl s[i]- do
if j and (j shl )= then
for k:= to shl s[i-]- do
if j and k= then f[i,j]:=(f[i,j]+f[i-,k]) mod mo;
end;
for j:= to shl s[i]- do
inc(dp,f[i,j]);
end; begin
readln(n);
ans:=;
for i:= to n do
if not v[i] then
ans:=ans*dp(i) mod mo; //这显然是乘法原理
writeln(ans);
end.