比赛 20120708 评测结果 TTAAAAAAAA
题目名称 项链制作 最终得分 80
用户昵称 IMSL77 运行时间 3.020 s
代码语言 Pascal 内存使用 1.17 MiB
提交时间 2012-07-08 11:57:53
显示代码纯文本
program necklacemn;
type
  integer=longint;
const
  maxn=16;
  pmod=1000000007;
var
  n:integer;
  w:array[1..maxn,1..maxn] of int64;
  f,g:array[0..1 shl maxn] of int64;

  procedure Fopen;
  begin
    assign(input,'necklacemn.in'); reset(input);
    assign(output,'necklacemn.out'); rewrite(output);
  end;

  procedure Fclose;
  begin
    close(input); close(output);
  end;

  procedure Init;
  var
    i,j:integer;
  begin
    readln(n);
    for i:=1 to n do
    for j:=1 to n do
      read(w[i,j]);
  end;

  procedure Dp;
  var
    i,j,k:integer;
  begin
    fillchar(g,sizeof(g),0);
    g[0]:=1;
    for j:=1 to 1 shl n-1 do
    begin
      for i:=1 to n do if j and (1 shl (i-1))>0 then break;
      g[j]:=g[j-1 shl (i-1)];
      for k:=1 to n do if (k<>i) and (j and (1 shl (k-1))>0) then
        g[j]:=g[j]*(w[i,k]+1) mod pmod;
    end;
    fillchar(f,sizeof(f),0);
    f[0]:=1;
    for j:=1 to 1 shl n-1 do
    begin
      for i:=1 to n do if j and (1 shl (i-1))>0 then break;
      for k:=1 to j-1 do
      if (k and (1 shl (i-1))>0) and (j or k=j) then
        f[j]:=(f[j]+f[k]*g[j-k]) mod pmod;
      f[j]:=(g[j]-f[j]+pmod) mod pmod;
    end;
    writeln(f[1 shl n-1]);
  end;

begin
  Fopen;
  Init;
  Dp;
  Fclose;
end.