从m中取出n个全组合

来源:互联网 发布:张大奕的淘宝店劣质 编辑:程序博客网 时间:2024/05/17 06:41

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class mAn {
public static int count = 0;
public static void main(String[] args) {
String[] n ={“1”,”2”,”3”,”4”};
List lst = Arrays.asList(n);
take(“”, 4, lst);
System.out.println(count);
}

public static void take(String s, int total, List lst) {      for (int i = 0; i < lst.size(); i++) {        List tempList = new ArrayList(lst);        String n = tempList.remove(i) + s;        if(total == 1){            count ++;            System.out.println(n);        }        else{            int temp = total - 1;            take(n, temp, tempList);        }    }}  

}

阅读全文
0 0