本帖最后由 likejian 于 2010-05-31 20:15:56 编辑

解决方案 »

  1.   

    简单的用for循环,一个个去排列
      

  2.   

      for i := 1 to 8 do
      begin
        for j:= (i+1) to 8 do
        begin
          Memo1.Lines.Add(IntToStr(a[i]) + ',' + IntToStr(a[j]));
        end;
      end;这是选出数据后排列的代码,但选出数据的代码我也不知道,查了下网站需要用到递归,比较复杂,等待高手能够写出从M个数中取中N个数的组合代码
      

  3.   

    递归算法procedure TForm1.Button1Click(Sender: TObject);
    var
      s1,s2:string;
      str,str1:TStrings;
      i,j,m,n:Integer;
    begin
      s1:=Trim(self.Edit1.Text);//这里就是你的字符串‘4,6,8,12,16,17,20,28,29,30,31’
      s2:=Trim(self.Edit2.Text);//这里输入8
      if (s1='') or (s2='') then
        Exit;
      str:=TStringList.Create;
      str.Clear;
      str1:=TStringList.Create;
      str1.Clear;
      self.getn(s1,'',StrToInt(s2),str);
      i:=str.Count;
      self.Memo1.Lines.Clear;
      for j:=0 to i-1 do
      begin
        s1:=str.Strings[j];
        self.Memo1.Lines.Add(s1);
      end;
    end;procedure TForm1.getn(ss, ss1: string; count: Integer; var str: TStrings);
    var
      i,j,m,n:Integer;
      s,s1,s2,s3:string;
      str1,str2:TStrings;
    begin
      str1:=TStringList.Create;
      str1.Clear;
      str2:=TStringList.Create;
      str2.Clear;
      ExtractStrings([','],[],PChar(ss),str1);
      i:=str1.Count;
      if i=0 then
        Exit;
      for j:=1 to i do
      begin
        s1:=str1.Strings[j-1];
        if ss1='' then
          s3:=ss1+s1
        else
          s3:=ss1+'|'+s1;
        str2.Clear;
        ExtractStrings(['|'],[],PChar(s3),str2);
        if str2.Count=count then
        begin
          str.Add(s3);
          Continue;
        end;
        s2:='';
        for n:=j to i-1 do
          s2:=s2+str1.Strings[n]+',';
        Self.getn(s2,s3,count,str);
      end;
    end;
      

  4.   

    --C(11,3)=165种CREATE TABLE #(id int)
    INSERT INTO #
    SELECT 4 UNION ALL
    SELECT 6 UNION ALL
    SELECT 8 UNION ALL
    SELECT 12 UNION ALL
    SELECT 16 UNION ALL
    SELECT 17 UNION ALL
    SELECT 20 UNION ALL
    SELECT 28 UNION ALL
    SELECT 29 UNION ALL
    SELECT 30 UNION ALL
    SELECT 31SELECT A.id,B.id,C.id,D.id,E.id,F.id,G.id,I.id
    FROM # A ,# B ,# C,# D,# E,# F,# G,# I 
    WHERE A.id<B.id AND B.ID<C.ID AND C.ID<D.ID
    AND D.ID<E.ID AND E.ID<F.ID AND F.ID<G.ID AND G.ID<I.ID/*
    id          id          id          id          id          id          id          id          
    ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 
    4           6           8           12          16          17          20          28
    4           6           8           12          16          17          20          29
    4           6           8           12          16          17          20          30
    4           6           8           12          16          17          20          31
    4           6           8           12          16          17          28          29
    4           6           8           12          16          17          28          30
    4           6           8           12          16          17          28          31
    4           6           8           12          16          17          29          30
    4           6           8           12          16          17          29          31
    4           6           8           12          16          17          30          31
    4           6           8           12          16          20          28          29
    4           6           8           12          16          20          28          30
    4           6           8           12          16          20          28          31
    4           6           8           12          16          20          29          30
    4           6           8           12          16          20          29          31
    4           6           8           12          16          20          30          31
    4           6           8           12          16          28          29          30
    4           6           8           12          16          28          29          31
    4           6           8           12          16          28          30          31
    4           6           8           12          16          29          30          31
    4           6           8           12          17          20          28          29
    4           6           8           12          17          20          28          30
    4           6           8           12          17          20          28          31
    4           6           8           12          17          20          29          30
    4           6           8           12          17          20          29          31
    4           6           8           12          17          20          30          31
    4           6           8           12          17          28          29          30
    4           6           8           12          17          28          29          31
    4           6           8           12          17          28          30          31
    4           6           8           12          17          29          30          31
    4           6           8           12          20          28          29          30
    4           6           8           12          20          28          29          31
    4           6           8           12          20          28          30          31
    4           6           8           12          20          29          30          31
    4           6           8           12          28          29          30          31
    4           6           8           16          17          20          28          29
    4           6           8           16          17          20          28          30
    4           6           8           16          17          20          28          31
    4           6           8           16          17          20          29          30
    4           6           8           16          17          20          29          31
    4           6           8           16          17          20          30          31
    4           6           8           16          17          28          29          30
    4           6           8           16          17          28          29          31
    4           6           8           16          17          28          30          31
    4           6           8           16          17          29          30          31
    4           6           8           16          20          28          29          30
    4           6           8           16          20          28          29          31
    4           6           8           16          20          28          30          31
    4           6           8           16          20          29          30          31
    4           6           8           16          28          29          30          31
    4           6           8           17          20          28          29          30
    4           6           8           17          20          28          29          31
    4           6           8           17          20          28          30          31
    4           6           8           17          20          29          30          31
    4           6           8           17          28          29          30          31
    4           6           8           20          28          29          30          31
    4           6           12          16          17          20          28          29
    4           6           12          16          17          20          28          30
    4           6           12          16          17          20          28          31
    4           6           12          16          17          20          29          30
    4           6           12          16          17          20          29          31
    4           6           12          16          17          20          30          31
    4           6           12          16          17          28          29          30
    4           6           12          16          17          28          29          31
    4           6           12          16          17          28          30          31
    4           6           12          16          17          29          30          31
    4           6           12          16          20          28          29          30
    4           6           12          16          20          28          29          31
    4           6           12          16          20          28          30          31
    4           6           12          16          20          29          30          31
    4           6           12          16          28          29          30          31
    4           6           12          17          20          28          29          30
    4           6           12          17          20          28          29          31
    4           6           12          17          20          28          30          31
    4           6           12          17          20          29          30          31
    4           6           12          17          28          29          30          31
    4           6           12          20          28          29          30          31
    4           6           16          17          20          28          29          30
    4           6           16          17          20          28          29          31
    4           6           16          17          20          28          30          31
    4           6           16          17          20          29          30          31
    4           6           16          17          28          29          30          31
    4           6           16          20          28          29          30          31
    4           6           17          20          28          29          30          31
    4           8           12          16          17          20          28          29
    4           8           12          16          17          20          28          30
    4           8           12          16          17          20          28          31
    4           8           12          16          17          20          29          30
      

  5.   


    4           8           12          16          17          20          29          31
    4           8           12          16          17          20          30          31
    4           8           12          16          17          28          29          30
    4           8           12          16          17          28          29          31
    4           8           12          16          17          28          30          31
    4           8           12          16          17          29          30          31
    4           8           12          16          20          28          29          30
    4           8           12          16          20          28          29          31
    4           8           12          16          20          28          30          31
    4           8           12          16          20          29          30          31
    4           8           12          16          28          29          30          31
    4           8           12          17          20          28          29          30
    4           8           12          17          20          28          29          31
    4           8           12          17          20          28          30          31
    4           8           12          17          20          29          30          31
    4           8           12          17          28          29          30          31
    4           8           12          20          28          29          30          31
    4           8           16          17          20          28          29          30
    4           8           16          17          20          28          29          31
    4           8           16          17          20          28          30          31
    4           8           16          17          20          29          30          31
    4           8           16          17          28          29          30          31
    4           8           16          20          28          29          30          31
    4           8           17          20          28          29          30          31
    4           12          16          17          20          28          29          30
    4           12          16          17          20          28          29          31
    4           12          16          17          20          28          30          31
    4           12          16          17          20          29          30          31
    4           12          16          17          28          29          30          31
    4           12          16          20          28          29          30          31
    4           12          17          20          28          29          30          31
    4           16          17          20          28          29          30          31
    6           8           12          16          17          20          28          29
    6           8           12          16          17          20          28          30
    6           8           12          16          17          20          28          31
    6           8           12          16          17          20          29          30
    6           8           12          16          17          20          29          31
    6           8           12          16          17          20          30          31
    6           8           12          16          17          28          29          30
    6           8           12          16          17          28          29          31
    6           8           12          16          17          28          30          31
    6           8           12          16          17          29          30          31
    6           8           12          16          20          28          29          30
    6           8           12          16          20          28          29          31
    6           8           12          16          20          28          30          31
    6           8           12          16          20          29          30          31
    6           8           12          16          28          29          30          31
    6           8           12          17          20          28          29          30
    6           8           12          17          20          28          29          31
    6           8           12          17          20          28          30          31
    6           8           12          17          20          29          30          31
    6           8           12          17          28          29          30          31
    6           8           12          20          28          29          30          31
    6           8           16          17          20          28          29          30
    6           8           16          17          20          28          29          31
    6           8           16          17          20          28          30          31
    6           8           16          17          20          29          30          31
    6           8           16          17          28          29          30          31
    6           8           16          20          28          29          30          31
    6           8           17          20          28          29          30          31
    6           12          16          17          20          28          29          30
    6           12          16          17          20          28          29          31
    6           12          16          17          20          28          30          31
    6           12          16          17          20          29          30          31
    6           12          16          17          28          29          30          31
    6           12          16          20          28          29          30          31
    6           12          17          20          28          29          30          31
    6           16          17          20          28          29          30          31
    8           12          16          17          20          28          29          30
    8           12          16          17          20          28          29          31
    8           12          16          17          20          28          30          31
    8           12          16          17          20          29          30          31
    8           12          16          17          28          29          30          31
    8           12          16          20          28          29          30          31
    8           12          17          20          28          29          30          31
    8           16          17          20          28          29          30          31
    12          16          17          20          28          29          30          31(165 row(s) affected)
    */
      

  6.   

    如果是算P(11,8)的话就算了,我用sql跑了10分钟都没出结果。
    如果用delphi做的话一定要用线程来做。