记录编号 16123 评测结果 AAATTTT
题目名称 圆桌会议B 最终得分 42
用户昵称 Gravatarybh 是否通过 未通过
代码语言 Pascal 运行时间 4.005 s
提交时间 2010-04-20 17:37:41 内存使用 0.88 MiB
显示代码纯文本
program dislike;
type
  t=array[1..40] of integer;
var
  ans:array[1..10000] of t;
  a:t;
  b:array[1..40] of boolean;
  like:array[1..40,1..40] of boolean;
  n,c,k,i,j,r,du:integer;
  bb:boolean;

procedure dfs(step,last:integer);
var
  i,j1,j2:integer;
  bool,bool2:boolean;
begin
  for i:=1 to n do
    if (b[i]) and (like[last,i]) and (like[i,last]) then
    begin
      a[step]:=i;
      if step=n then
      begin
        if (like[i,1]) and (like[1,i]) then
        begin
          bool2:=true;
          for j1:=1 to k do
          begin
            bool:=false;
            for j2:=2 to n do
              if a[j2]<>ans[j1,n+2-j2] then
              begin
                bool:=true;
                break
              end;
            if bool=false then
            begin
              bool2:=false;
              break
            end
          end;
          if bool2 then
          begin
            inc(k);
            ans[k]:=a;
          end
        end
      end
      else
      begin
        b[i]:=false;
        dfs(step+1,i);
        b[i]:=true;
      end;
    end
end;

begin
  assign(input,'dislike.in');
  reset(input);
  assign(output,'dislike.out');
  rewrite(output);
  repeat
    read(c);
    if c=0
      then break;
    if c>1
      then writeln;
    readln(n);
    bb:=true;
    for i:=1 to n do
    begin
      du:=0;
      for j:=1 to n do
      begin
        read(r);
        if r=1
          then like[i,j]:=false
          else
          begin
            like[i,j]:=true;
            du:=du+1;
          end
      end;
      if du=1 then
      begin
        writeln(c,' ',k);
        bb:=false;
        break
      end;
    end;
    if bb=false
      then continue;
    k:=0;
    fillchar(b,sizeof(b),true);
    b[1]:=false;
    a[1]:=1;
    dfs(2,1);
    writeln(c,' ',k);
    if k>0 then
    begin
      for i:=1 to k do
      begin
        for j:=1 to n do
          write(ans[i,j],' ');
        writeln
      end
    end;
  until false;
  close(input);
  close(output);
end.