比赛 暑假培训三 评测结果 WWWWWW
题目名称 数列问题 最终得分 0
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-19 10:19:01
显示代码纯文本
program dfs3;
type
shuzu=array[1..1000]of integer;
shuzu2=array[1..50] of boolean;
shuzu1=array[1..100] of integer;
var
s:shuzu;
s1:shuzu1;
f:shuzu2;
i,j,n,m,k,a,b:integer;
c:longint;
f1,f2:text;
flag,flag1:boolean;
procedure print;
var
i,j:integer;
  begin
   inc(c);
   for i:=1 to n do
   begin
     write(f2,s[i],' ');
      end;
      writeln(f2);
        end;
procedure try(x,y:integer);
var
 j,k,v:integer;
 begin
   if y>n then print
          else
           begin
             for k:=1 to n do
               begin
               flag:=false; flag1:=false;
                  for j:=1 to m do
                   if (s1[j]=k+s[y-1])and(f[k]=true) then flag:=true;
               if f[k] and flag then begin
                  f[k]:=false;
                  s[y]:=k;
                  try(x-1,y+1);
                  end;
                  end;
                  end;
  end;
begin
assign(f1,'dfs3.in');reset(f1);
assign(f2,'dfs3.out');rewrite(f2);
readln(f1,n);
c:=0;  m:=3;s1[1]:=2;s1[2]:=3;
for i:=5 to 100 do
begin
   flag:=true;
     for j:=2 to trunc(sqrt(i)) do
       if i mod j=0 then flag:=false;
      if flag=true then begin s1[m]:=i;
      m:=m+1;                 end;
      end;
for i:=1 to n do
begin
for j:=1 to n do
f[j]:=true;
s[1]:=i;
f[i]:=false;
try(n-1,2);
end;
writeln(f2,c);
close(f2);
end.