比赛 NOIP_3 评测结果 WTAAAAAAAA
题目名称 填数 最终得分 80
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-12 22:16:29
显示代码纯文本
program exday3_2;
 const
  sushu:array[1..242] of integer=(0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,
                                  0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,
                                  0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,
                                  0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,
                                  1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
                                  0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,
                                  1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,
                                  0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,
                                  0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
                                  0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0
);
 var
    n:integer;
    used:array[1..121] of boolean;
    a:array[0..11,0..11] of integer;

 procedure print;
  var
     i,j:integer;
 begin
  for i:=1 to n do
   begin
   for j:=1 to n-1 do
   write(a[i,j],' ');
   writeln(a[i,n]);
   end;
  close(input); close(output);
  halt;
 end;


 procedure search(h,k:integer);
  var
     i:integer;
  begin
   if k>n then begin inc(h); k:=1 end;
   if h>n then print;

   for i:=1 to n*n do
    if not used[i]
    then
     if   ( (h>1) and (sushu[a[h-1,k]+i]=1) or (h=1) )
     and  ( (k>1) and (sushu[a[h,k-1]+i]=1) or (k=1) )
    then
        begin
        a[h,k]:=i;
        used[i]:=true;
        search(h,k+1);
        used[i]:=false;
        a[h,k]:=0
        end;
  end;

 begin
  assign(input,'tianshu.in');
  assign(output,'tianshu.out');
  reset(input); rewrite(output);
  read(n);
  fillchar(used,sizeof(used),0);
  a[1,1]:=1; used[1]:=true;
  search(1,2);
  writeln('NO');
  close(input); close(output);
 end.