比赛 |
NOIP_4 |
评测结果 |
AAAAAT |
题目名称 |
数列问题 |
最终得分 |
83 |
用户昵称 |
Hamster |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-19 20:42:59 |
显示代码纯文本
program dfs3;
const
ss:array[1..9] of integer=(3,5,7,11,13,17,19,23,29);
var
a:array[1..15] of integer;
b:array[1..15] of boolean;
s:array[1..30] of boolean;
n,nn:integer;
q:longint;
fin,fout:text;
procedure init;
var
i,j,r:integer;
l:boolean;
begin
readln(fin,n);
for i:=1 to n do
begin
a[i]:=0;
b[i]:=true;
end;
for i:=1 to 30 do s[i]:=false;
q:=0;
for i:=1 to 9 do s[ss[i]]:=true;
end;
procedure print;
var
i:integer;
begin
for i:=1 to n do write(fout,a[i],' ');
writeln(fout);
inc(q);
end;
procedure search(aa,t:integer);
var
k:integer;
begin
for k:=1 to n do
if b[k] and s[k+aa]then
begin
a[t]:=k;
b[k]:=false;
if t=n then print
else search(k,t+1);
a[t]:=0;
b[k]:=true;
end;
end;
begin
assign(fin,'dfs3.in');
reset(fin);
assign(fout,'dfs3.out');
rewrite(fout);
init;
for nn:=1 to n do
begin
b[nn]:=false;
a[1]:=nn;
search(nn,2);
b[nn]:=true;
end;
writeln(fout,q);
close(fin);
close(fout);
end.