Description
Input
Output
Sample Input
3 3
1 2 3 4 5 6
1 2 3 0 0 0
0 0 0 4 5 6
1 2 3 4 5 6
1 2 3 0 0 0
0 0 0 4 5 6
Sample Output
2
HINT
题解:
一脸容斥的样子。
枚举判断是否相同的泉水集合S,若|S|>=K,则inc(ANS,(-1)^(|S|-K)*C(|S|,K)*相同对数)。
用哈希表记录、判断(我之前竟然写了类似字符串哈希的的做法,哈希值相同直接判断相同,WA惨了)。
代码:
var
i,j,k,l,n,m:longint;
f:array[..,..]of int64;
b:array[..]of longint;
c:array[..,..]of int64;
cc:array[..]of longint;
d:array[..,-..]of longint;
a:array[..]of int64;
ans:int64;
procedure find(x,z:longint;y:int64);
var i,j,l:longint;
begin
i:=cc[a[z]];
while i> do
begin
l:=;
for j:= to x do if d[i,j]<>f[z,b[j]] then begin l:=; break; end;
if l= then begin ans:=ans+y*d[i,]; inc(d[i,]); exit; end;
i:=d[i,-];
end;
inc(m); for i:= to x do d[m,i]:=f[z,b[i]];
d[m,]:=; d[m,-]:=cc[a[z]]; cc[a[z]]:=m;
end;
function ss2(x:longint;y:int64):int64;
var i,j,k:longint;
begin
ss2:=; m:=;
for i:= to do cc[i]:=;
for i:= to n do
begin
a[i]:=;
for j:= to x do a[i]:=(a[i]*+f[i,b[j]])mod ;
find(x,i,y);
end;
end;
procedure ss(x,y:longint);
var i:longint;
begin
if x> then
begin
if y>=k then
begin
if(y-k)mod = then ss2(y,c[y,k])
else ss2(y,-c[y,k]);
end;
exit;
end;
ss(x+,y);
inc(y); b[y]:=x; ss(x+,y);
end;
begin
c[,]:=;
for i:= to do
begin
c[i,]:=; c[i,i]:=;
for j:= to i- do c[i,j]:=c[i-,j-]+c[i-,j];
end;
readln(n,k);
for i:= to n do
for j:= to do read(f[i,j]);
ss(,);
writeln(ans);
end.