不是VIP会员,不能显示答案

题目解答

题目:
(排列数)输入两个正整数 ,在 中任取 个数,按字典序从小到大输出所有这样的排列。例如
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
const
   SIZE=20;
var
   used:array [1..SIZE] of boolean;
   data:array [1..SIZE] of integer;
   n,m,i,j,k:integer;
   flag:boolean;

begin
   readln(n,m);
   fillchar(used,sizeof(used),false);
   for i:=1 to m do
   begin
    data[i] := i;
    used[i]   := true;
   end;
   flag := true;
   while flag do
   begin
      for i:=1 to m-1 do write(data[i],' ');
      writeln(data[m]);
      flag :=  false  ;
      for i := m downto 1 do
      begin
           used[data[i]]:=false  ;
         for j := data[i]+1 to n do if used[j] = false then
         begin
          used[j] := true;
          data[i] :=  j   ;
            flag := true;
            break;
         end;
         if flag then
         begin
            for k:= i+l to m do
               for j:= 1 to  n  do if used[j]=false then
               begin
                  data[k] := j;
                  used[j] := true;
                  break;
               end;
               break   ;
         end;
      end;
   end;
end.
考点:
分析:
解答:
评论:
老师: