递归求组合:
const n=5;
s0='红黄兰白黑';
type
charray=array[1..n] of string[2];
boolarray=array[1..n] of boolean;
var
s,ss:string;
ch:charray;
t:boolarray;
i,m,num:integer;
procedure next(t:boolarray;ss:string;m:integer;var num:integer);
var
i:integer;
begin
if m=0 then begin writeln(ss); inc(num); end
else
for i:=1 to n do
if t[i] then begin
t[i]:=false;
next(t,ss+ch[i],m-1,num);
end;
end;
begin
s:=copy(s0,1,length(s0));
for i:=1 to n do begin ch[i]:=copy(s,2*i-1,2); t[i]:=true; end;
ss:='';
m:=3;
next(t,ss,m,num);
writeln;
writeln(num);
end.