记录编号 2399 评测结果 AAAAAT
题目名称 [HAOI 2004模拟]数列问题 最终得分 83
用户昵称 GravatarNickName 是否通过 未通过
代码语言 Pascal 运行时间 1.175 s
提交时间 2008-09-20 13:57:31 内存使用 0.11 MiB
显示代码纯文本
program dfs3;
type jh=set of 1 .. 30;
const sushu:jh=[2,3,5,7,11,13,17,19,23,29];
var ddi,ddo:text;
n:longint;
x1,x2:longint;
pai:array[1..15] of integer;
nn:jh;
jg:longint;
t:longint;
procedure wri;
var x:integer;
begin
for x:=1 to n-1 do
write(ddo,pai[x],' ');
writeln(ddo,pai[n]);
jg:=jg+1;
end;
procedure go;
var x:integer;
begin
if t=1 then
for x:=1 to n do
begin
nn:=nn+[x];
pai[1]:=x;
t:=t+1;
go;
t:=t-1;
nn:=nn-[x];
end;
if t>1 then
for x:=1 to n do
if (not(x in nn)) and (x+pai[t-1] in sushu) then
begin
pai[t]:=x;
nn:=nn+[x];
if t<n then
begin
t:=t+1;
go;
t:=t-1;
end;
nn:=nn-[x];
if t=n then wri;
end;
end;
begin
assign(ddi,'dfs3.in');
reset(ddi);
readln(ddi,n);
close(ddi);
assign(ddo,'dfs3.out');
rewrite(ddo);
jg:=0;
nn:=[];
t:=1;
go;
writeln(ddo,jg);
close(ddo);
end.