比赛 |
NOIP_4 |
评测结果 |
WWWWWT |
题目名称 |
数列问题 |
最终得分 |
0 |
用户昵称 |
Achilles |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-19 21:50:18 |
显示代码纯文本
program dfs3;
var
n,n2,i,j,k,p:longint;
sz:array[0..50,0..50]of integer;
answer,hx:array[1..50]of integer;
procedure find(c:integer);
var
i:integer;
begin
if c>n then begin
for k:=1 to n-1 do
begin
write(answer[k],' ');
end;
write(answer[n]);
writeln;
n2:=n2+1;
end
else begin
for i:=1 to sz[c-1,0] do
begin
if hx[sz[c-1,i]]=0 then begin
hx[sz[c-1,i]]:=1;
answer[c]:=sz[c-1,i];
find(c+1);
hx[sz[c-1,i]]:=0;
end;
end;
end;
end;
begin
assign(input,'dfs3.in');
assign(output,'dfs3.out');
reset(input);
rewrite(output);
readln(n);
fillchar(sz,sizeof(sz),0);
fillchar(hx,sizeof(hx),0);
sz[0,0]:=n;
for i:=1 to n do
sz[0,i]:=i;
for i:=1 to n do
for j:=1 to n do
begin
if i<>j then begin
p:=0;
for k:=2 to i+j-1 do
if (i+j)mod k=0 then begin
p:=1;
break;
end;
if p=0 then begin
sz[i,0]:=sz[i,0]+1;
sz[i,sz[i,0]]:=j;
end;
end;
end;
n2:=0;
find(1);
writeln(n2);
close(input);
close(output);
end.