看到n<=16不难想到状压dp
我们用二进制表示前x个位置,哪些牛被已经被选过了
这里我们可以通过穷举二进制数的顺序来转移
所以二维就够了
var a:array[..] of longint;
f:array[.. shl ,..] of int64;
n,i,j,k,m,t:longint;
ans:int64; begin
readln(n,t);
for i:= to n- do
readln(a[i]);
m:= shl n-;
for i:= to n- do
f[ shl i,i]:=;
for i:= to m do
for j:= to n- do
if (i and ( shl j)<>) then
begin
for k:= to n- do
if (i and ( shl k)=) and (abs(a[j]-a[k])>t) then
inc(f[i or ( shl k),k],f[i,j]);
end; ans:=;
for i:= to n- do
ans:=ans+f[m,i];
writeln(ans);
end.