有10个变量,每个变量可能是1,2,3这三个数。怎样用算法把所有的排列列举出来?
比如:
1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,2
1,1,1,1,1,1,1,1,1,3,
1,1,1,1,1,1,1,1,2,1
1,1,1,1,1,1,1,1,2,2
......要求
1用递归
2不用递归答出一个给一半分,两个分全给。
比如:
1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,2
1,1,1,1,1,1,1,1,1,3,
1,1,1,1,1,1,1,1,2,1
1,1,1,1,1,1,1,1,2,2
......要求
1用递归
2不用递归答出一个给一半分,两个分全给。
123
132213231312321function ZsList(mStr: string): string; { 全排列 }procedure pZsList(mLeft, mRight: string);varI, L: Integer;Temp: string;beginL := Length(mLeft);if L = 0 thenResult := Result + mRight + #13#10else for I := 1 to L do beginTemp := mLeft;Delete(Temp, I, 1);pZsList(Temp, Concat(mRight, mLeft[I]));end;end; { [ZsList<pZsList>] }beginResult := '';pZsList(mStr, '');end; { ZsList }