1. 程式人生 > >從m中取出n個全組合

從m中取出n個全組合

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);
        }
    }




}  

}