...implementation{$R *.dfm}var a:array[0..100] of integer;
n:integer;
r:integer=3;//procedure HS(t: integer;AList:TStrings);//用回溯法进行组合var i:Integer;
s:string;
begin
if t>r then
begin
s:=inttostr(a[1]);
for i:=2 to rdo
s:=s+','+IntToStr(a);
AList.Add(s);
end else
begin
for i:=1 to ndo
begin
a[t]:=i;
if (a[t-1]<a[t]) then
HS(t+1,AList);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);var sList,sList2:TStringList;
i,j:integer;
s:string;
begin
sList:=TStringList.Create;
try sList.Delimiter:=',';
sList.DelimitedText:=trim(Edit1.Text);
n:=sList.Count;
Memo1.Clear;
HS(1,Memo1.Lines);
sList2:=TStringList.Create;
try for i:=0 to Memo1.Lines.Count-1do
begin
sList2.Delimiter:=',';
sList2.DelimitedText:=Memo1.Lines;
s:=sList[StrToInt(sList2[0])-1];
for j:=1 to sList2.Count-1do
s:=s+','+sList[StrToInt(sList2[j])-1];
Memo1.Lines:=s;
end;
finally sList2.Free;
end;
finally sList.Free;
end;
end;