记录编号 12102 评测结果 AAAAAT
题目名称 [HAOI 2004模拟]数列问题 最终得分 83
用户昵称 GravatarReimBurSe. 是否通过 未通过
代码语言 Pascal 运行时间 1.067 s
提交时间 2009-09-02 21:54:38 内存使用 0.12 MiB
显示代码纯文本
Program dfs3;

Type
sc=array [0..50,0..50] of integer;
sc1=array [0..50] of integer;
sc2=array [1..50] of boolean;
sc3=array [1..100] of boolean;

Var
i,j,o,z:longint;
n:integer;
fangan:sc;
s:sc1;
panduan:sc2;
sushu:sc3;

Procedure print;
Var i:integer;
begin
 for i:=1 to n do write(s[i],' ');
 writeln;
 z:=z+1;
end;

Procedure aaa(i:integer);
Var p,q:integer;
Begin
 for p:=1 to fangan[s[i-1],0] do begin
  if panduan[fangan[s[i-1],p]]=true then begin
   panduan[fangan[s[i-1],p]]:=false;
   s[i]:=fangan[s[i-1],p];
   if i=n then print
   else aaa(i+1);
   panduan[fangan[s[i-1],p]]:=true;
  end;
 end;
End;

Begin
assign(input,'dfs3.in');
assign(output,'dfs3.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to (n*2) do sushu[i]:=false;
sushu[2]:=true;
sushu[3]:=true;
sushu[5]:=true;
sushu[7]:=true;
sushu[11]:=true;
sushu[13]:=true;
sushu[17]:=true;
sushu[19]:=true;
sushu[23]:=true;
sushu[29]:=true;
sushu[31]:=true;
sushu[37]:=true;
sushu[41]:=true;
sushu[43]:=true;
sushu[47]:=true;
for i:=1 to n do fangan[i,0]:=0;
for i:=1 to n do begin
 for j:=1 to n do begin
  if (sushu[i+j]=true)and(i<>j) then begin
   fangan[i,0]:=fangan[i,0]+1;
   fangan[i,fangan[i,0]]:=j;
  end;
 end;
end;
for i:=1 to n do panduan[i]:=true;
z:=0;
s[0]:=0;
fangan[0,0]:=n;
for i:=1 to n do fangan[0,i]:=i;
aaa(1);
writeln(z);
if z=0 then writeln('0');
close(input);
close(output);
End.