记录编号 39327 评测结果 AAAAAAAAAA
题目名称 项链制作 最终得分 100
用户昵称 GravatarSnowDancer 是否通过 通过
代码语言 Pascal 运行时间 1.126 s
提交时间 2012-07-09 11:50:12 内存使用 1.17 MiB
显示代码纯文本
const
  base=1000000007;
var
  log2,low:array[0..65536] of longint;
  f,g:array[0..65536] of longint;
  c:array[1..16,1..16] of int64;
  n,i,j,k,l:longint;
begin
assign(input,'necklacemn.in'); reset(input);
assign(output,'necklacemn.out'); rewrite(output);
  readln(n);
  for i:=1 to n do
    for j:=1 to n do
      read(c[i,j]);
  g[0]:=1;
  for i:=1 to 1<<n-1 do begin
    low[i]:=low[i-1]; log2[i]:=log2[i-1];
    if i and (i-1)=0 then begin
      low[i]:=i;inc(log2[i]);
    end;
  end;
  for i:=1 to 1<<n-1 do begin
    g[i]:=g[i-low[i]]; k:=log2[i];
    for j:=1 to log2[i]-1 do
      if 1<<(j-1) and i>0 then
        g[i]:=g[i]*(c[k,j]+1) mod base;
  end;
  f[0]:=1;
  for i:=1 to 1<<n-1 do begin
    f[i]:=g[i]; k:=i and (-i);
    j:=i and (i-1);
    while j<>0 do begin
      if k and j>0 then
        f[i]:=f[i]-int64(f[j])*g[i-j] mod base;
        while f[i]>=base do dec(f[i],base);
        while f[i]<0 do inc(f[i],base);
      dec(j); j:=j and i;
    end;
  end;
  writeln((f[1<<n-1]+base) mod base);
close(input); close(output);
end.