如何快速得到组合的结果并保存在STRINGLIST中呢?

解决方案 »

  1.   

    比如想知道从20个数里面取6个的所有组合,把这些组合的结果快速写入stringlist
      

  2.   

    max:= $01 shl (m - 1);
    i:=1;
    j:=0;
    while i < max do  begin
       if CountN(i) = n  then begin
         for j := 0 to m do
          if (  ( i  shr j ) and $01 ) = 1  then
           s:=s+IntToStr(1+j)+','; //生成组合序列
          sl.Add(s);
          end ;
       Inc(i);
       s:='';
    end;
    sl.Free;
      

  3.   

    m:=10;
    n:=6;
    sl:=TStringList.Create;其他方法查书吧..