- 全排列
- 2009-11-01 22:29:52 @
我是拿我原有的全排列程序来改的
program pl;
type arr=array[1..10000] of longint;
arr2=array[1..1000,1..1000] of longint;
var n,q,bn,i:longint;
a:arr;
b:arr2;
function pd(i,s:integer):boolean;
var i1:integer;
begin
pd:=true;
for i1:=1 to s-1 do
if a[i1]=i then
begin
pd:=false;
break;
end;
end;
procedure pl1(x:integer);
var i:integer;
begin
if x>n then
begin
for i:=1 to n do b[bn,i]:=a[i];
inc(bn);
end
else
begin
for i:=1 to n do
if pd(i,x) then
begin
a[x]:=i;
pl1(x+1);
end;
end;
end;
begin
readln(n,q);
bn:=1;
pl1(1);
for i:=1 to n do write(b[q,i],' ');
end.
0 条评论
目前还没有评论...