「算法与数据结构」排列组合
组合 1import java.util.*; 2 3public class Mains{ 4 public static List<List<Integer>> resultss = new ArrayList<>(); 5 6 public void combinations(List<Integer> selected, List<Integer> data, int num){ 7 if(num == 0){ 8 resultss.add(new ArrayList<Integer>(selected)); 9 return; 10 } 11 if(data.size() == 0 ){ 12 System.out.print(""); 13 return; 14 } 15 selected.add(data.get(0)); 16 combinations(selected, data.subList(1, data.size()), num -1); 17 selected.remove(data.get(0)); 18 combinations(selected, data.subList(1, data.size()), num ); 19 } 20 public static void main(String[] args) { 21 Mains combin = new Mains(); 22 int[] nums = new int[]{1,2,3,4,5}; 23 combin.