- 全排列
- 2009-07-24 16:01:35 @
var i,k,n,m,j:integer;
a:array[1..10000000] of integer;
procedure print;
var i:integer;
begin
inc(j);
if j=m then
begin
write(a[1]);
for i:=2 to n do
begin
write(a[i]:2);
end;
exit;
end;
end;
function mcf(k:integer):boolean;
var i:integer;
begin
mcf:=true;
for i:=1 to k-1 do
if a[i]=a[k] then begin mcf:=false; break; end;
end;
procedure try(k:integer);
var i:integer;
begin
if k>n then begin print; exit; end;
for i:=1 to n do
begin
a[k]:=i;
if mcf(k) then try(k+1);
end;
end;
BEGIN
readln(n,m);
try(1);
readln;
END.
1 条评论
-
610534898 LV 5 @ 2010-03-03 21:00:27
用哈希
用哈希判充
- 1