高分悬赏:Java语言怎么输出m个数字里选出n个数字的全部的排列组合,一行输出1个
有一种专门的排列组合算法可以了解一下。https://www.iteye.com/blog/liyuandong-737756
public static Stack<Integer> stack = new Stack<Integer>();
public static void main(String[] args) {
int[] m = {1, 2, 3, 4, 5, 6};
int n = 3;
f(m, n, 0, 0);
}
private static void f(int[] shu, int targ, int has, int cur) {
if (has == targ) {
System.out.println(stack);
return;
}
for (int i = cur; i < shu.length; i++) {
if (!stack.contains(shu[i])) {
stack.add(shu[i]);
f(shu, targ, has + 1, i);
stack.pop();
}
}
}