开发者

Java: Simple Combination of a set of element of k order

I have a set of numbers {'1','13','25','32','49',...}, i want to calculate all possible combinations of this numbers of order k.

Esample1:

set = {'1','5','23','41,'54','63'};
k = 4;

Output1:

1 5 23 41
1 5 23 54
1 5 23 63
1 5 41 54
1 5 41 63
1 5 54 63
1 23 41 54
1 23 41 63
1 23 54 63
1 41 54 63
5 23 41 54
开发者_Python百科5 23 41 63
5 23 54 63
5 41 54 63
23 41 54 63

Example2:

set = {'a','v','f','z'};
k=3;

Output2:

a v f
a v z
a f z
v f z

in Java plaese.

Thank you!


You should be able to find an appropriate algorithm in D.Knuth's The Art of Computer Programming, Volume 4, fascicle 3 - Generating All Combinations, which can be downloaded from his website.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜