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

荒凉一梦 提交于 2019-12-14 04:26:48

问题


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
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!


回答1:


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.



来源:https://stackoverflow.com/questions/3931775/java-simple-combination-of-a-set-of-element-of-k-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!