记录编号 6438 评测结果 AAAAAA
题目名称 [HAOI 2004模拟]数列问题 最终得分 100
用户昵称 Gravatar辨机ZN 是否通过 通过
代码语言 Pascal 运行时间 1.048 s
提交时间 2008-11-02 10:17:23 内存使用 0.12 MiB
显示代码纯文本
program ex(f1,f2);
 type
  zn=array [0..51,0..100] of integer;
  da=array [1..100] of boolean;
  ka=array [1..51] of integer;
  fa=array [1..51] of boolean;
 var
  a:zn; i,j,k,m,n,p,l,ans:longint; flag:boolean;
  f1,f2:text; ss:da; c:ka; pc:fa;
 procedure init;
  begin
   assign(f1,'dfs3.in'); reset(f1);
   assign(f2,'dfs3.out'); rewrite(f2);
   readln(f1,n);
  end;
 procedure sushu;
  var
   i,j,k,p:integer; flag:boolean;
  begin
    ss[2]:=true;
   for i:=3 to 100 do
    begin
    flag:=true;
    for j:=2 to trunc(sqrt(i)) do if i mod j=0 then begin flag:=false; break; end;
    if flag then ss[i]:=true;
    end;

   for i:=1 to n do
    for j:=1 to n do
     if (i<>j)and(ss[i+j]) then
      begin
       a[i,0]:=a[i,0]+1;
       a[i,a[i,0]]:=j;
      end;
  end;

  procedure dfs(step,x:integer);
   var
    i,j,k,p:integer;
   begin
    for i:=1 to a[x,0] do
     if pc[a[x,i]] then
     begin
      c[step]:=a[x,i]; pc[a[x,i]]:=false;
      if step=n then
       begin
        for j:=1 to n do write(f2,c[j],' ');
        writeln(f2);
        inc(ans);
        pc[a[x,i]]:=true;
       end
      else begin dfs(step+1,a[x,i]); pc[a[x,i]]:=true; end;
     end;
   end;

 begin
  init;
  sushu;
  for i:=1 to n do
   begin
    for j:=1 to n do pc[j]:=true;
    c[1]:=i; pc[i]:=false;
    dfs(2,i);
   end;
  writeln(f2,ans);
  close(f1);
  close(f2);
 end.