标题:
N个数选M个数组合,Java实现
[打印本页]
作者:
qingqing3721
时间:
2011-6-20 20:09
标题:
N个数选M个数组合,Java实现
import java. util. Set;
import java. util. HashSet;
public class Zuhe {
static void lottery(int a[], int start_index, int end_index,
int needed_balls, SetInteger already_chosen) {
if (needed_balls == 0) {
System. out. println(already_chosen);
return;
}
for (int i = start_index; i = end_index - needed_balls + 1; i++) {
already_chosen. add(a
);
lottery(a, i + 1, end_index, needed_balls - 1, already_chosen);
already_chosen. remove(a
);
}
}
public static void main(String[] args) {
lottery(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 9, 4,
new HashSetInteger());
}
}文章由
记忆枕汉妮威
整理,收集辛苦,希望能保留出处。
欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/)
Powered by Discuz! 6.0.0