记录编号 |
513 |
评测结果 |
AAAAAT |
题目名称 |
[HAOI 2004模拟]数列问题 |
最终得分 |
50 |
用户昵称 |
打不死的羊 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.069 s |
提交时间 |
2008-07-19 14:36:03 |
内存使用 |
0.00 MiB |
显示代码纯文本
Program dfs3;
type
arr=array[1..50]of integer;
var
n,ci,i:integer;
a,b:arr;
c:array[1..50,0..50]of integer;
procedure open;
begin
assign(input,'dfs3.in');
reset(input);
assign(output,'dfs3.out');
rewrite(output);
end;
function panduan(m:integer):boolean;
var
i:integer;
begin
if m=1 then begin panduan:=false; exit; end;
for i:=2 to m-1 do
if m mod i=0 then begin panduan:=false; exit; end;
panduan:=true;
end;
procedure chushi(n:integer);
var
i,j:integer;
begin
for i:=1 to n do
begin
c[i,0]:=0;
for j:=1 to n do
if (i<>j) and (panduan(i+j)=true) then
begin
inc(c[i,0]);
c[i,c[i,0]]:=j;
end;
end;
end;
procedure huisu(k:integer;a,b:arr);
var
i,j:integer;
begin
if k>n then
begin
for i:=1 to n do
write(output,a[i],' ');
writeln(output);
inc(ci);
exit;
end;
if k=1 then
for i:=1 to n do
begin
a[k]:=i;
b[i]:=1;
huisu(k+1,a,b);
b[i]:=0;
end
else
for i:=1 to c[a[k-1],0] do
begin
j:=c[a[k-1],i];
if b[j]=0 then
begin
a[k]:=j;
b[j]:=1;
huisu(k+1,a,b);
b[j]:=0;
end;
end;
end;
Begin
open;
readln(input,n);
{fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
for i:=1 to 50 do fillchar(c[i],sizeof(c[i]),0); }
chushi(n);
ci:=0;
huisu(1,a,b);
write(output,ci);
close(input);
close(output);
End.