记录编号 |
3994 |
评测结果 |
AAAAAA |
题目名称 |
[HAOI 2004模拟]数列问题 |
最终得分 |
100 |
用户昵称 |
MayLava |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.983 s |
提交时间 |
2008-10-12 18:45:38 |
内存使用 |
0.11 MiB |
显示代码纯文本
program MayLava;
const
ss:array[1..9]of integer=(3,5,7,11,13,17,19,23,29);
var
a:array[1..15]of integer;
c:array[1..15]of boolean;
b:array[1..15,0..15]of integer;
n,sum,i:longint;
fout:text;
procedure start;
var
f:text;
i,j:integer;
begin
assign(f,'dfs3.in');
reset(f);
readln(f,n);
close(f);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
fillchar(c,sizeof(c),true);
sum:=0;
for i:=1 to n do
for j:=1 to 9 do
if (ss[j]-i>0) and (ss[j]-i<=n) then begin
inc(b[i,0]);
b[i,b[i,0]]:=ss[j]-i;
end;
end;
procedure print;
var
f:text;
i:integer;
begin
for i:=1 to n-1 do
write(fout,a[i],' ');
writeln(fout,a[n]);
end;
procedure hunt(p:integer);
var
i:integer;
begin
if p=n then begin
print;
inc(sum);
exit;
end;
for i:=1 to b[a[p],0] do begin
if c[b[a[p],i]] then begin
c[b[a[p],i]]:=false;
a[p+1]:=b[a[p],i];
hunt(p+1);
c[b[a[p],i]]:=true;
end;
end;
end;
BEGIN
assign(fout,'dfs3.out');
rewrite(fout);
start;
for i:=1 to n do begin
a[1]:=i;
c[i]:=false;
hunt(1);
c[i]:=true;
end;
writeln(fout,sum);
close(fout);
END.