- 全排列
- 2009-03-18 21:11:06 @
var
a,b,c:array[1..20] of longint;
n,m,total:longint;
procedure init;
var
i:longint;
begin
read(n,m);
for i:=1 to n do
a[i]:=i;
end;
procedure print;
var
k:longint;
begin
for k:=1 to n do write(b[k],' ');
end;
procedure f(i:longint);
var
j:longint;
begin
if i>n then
begin
inc(total);
if total=m then
begin
print;
end;
end;
for j:=1 to n do
if c[j]=0 then
begin
b[i]:=a[j];
c[j]:=1;
f(i+1);
c[j]:=0;
end;
end;
procedure main;
begin
f(1);
end;
begin
init;
main;
end.
2 条评论
-
wushinoi LV 10 @ 2009-03-19 11:52:09
.
此题为数学题,显然不能用DFS
-
2009-03-18 21:27:43@
问题多哦
你的c数组
是不是判断a【i】是否使用过的,建议使用boolean
c没有初始化啊
可能还有问题
- 1