比赛 暑假培训三 评测结果 C
题目名称 数列问题 最终得分 0
用户昵称 name:弓虽 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-19 10:47:56
显示代码纯文本
program dfs3(input,output,f1,f2);
 const c:array [1..25] of integer=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97);
 var
  sum,ans,l:longint;
  f1,f2:text;
  n:integer;
  a:array[1..51] of boolean;
  b:array[1..51] of integer;
  d:array[1..51] of integer;
procedure print;
 var z:longint;
 begin
   for z:=1 to n do write(f2,b[z],' ');
   writeln(f2);
   end;
function panduan(sum:integer):boolean;
var i:longint;
begin
panduan:=false;
 for i:=1 to 25 do begin
  if (c[i]=sum) then
  begin
  panduan:=true;
   if panduan then exit;
   end;
  end;
    end;
procedure fuqiang(i:longint);
 var
  k:longint;
 begin
   for k:=1 to n do begin
   d[k]:=k;
   if k=1 then sum:=b[k]+d[k]
   else
    sum:=b[k-1]+d[k];
    if (a[k]=true) and ((i=1) or panduan(sum)=true)
     then begin
     a[k]:=false;
       b[i]:=k;
       if i=n then begin
         ans:=ans+1; print; end
         else
          fuqiang(i+1);
          a[k]:=true;
          b[i]:=0;
         end;
       end;
     end;
begin
 assign(f1,'dfs3.in');
 assign(f2,'dfs3.out');
 reset(f1);
 rewrite(f2);
 readln(f1,n);
 close(f1);
 sum:=0;
 for l:=1 to n do a[l]:=true;
 ans:=0;
 fuqiang(1);
 writeln(f2,ans);
 close(f2);
 end.