package com.xxx.xxxx.template.service; import java.util.ArrayList; import java.util.List; /** * 测试ZuoConTest 类 */ public class ZuoConTest { private static char[] is = new char[] { '1', '2', '4', '5'}; private static int total; private static int m = 3; public static void main(String[] args) { List<Integer> iL = new ArrayList<Integer>(); new ZuoConTest().plzh("", iL, m); System.out.println("total : " + total); } private void plzh(String s, List<Integer> iL, int m) { if(m == 0) { System.out.println(s); total++; return; } List<Integer> iL2; for(int i = 0; i < is.length; i++) { iL2 = new ArrayList<Integer>(); iL2.addAll(iL); if(!iL.contains(i)) { String str = s + is[i]; iL2.add(i); plzh(str, iL2, m-1); } } } }
Java-排列组合算法(包含重复)
猜你喜欢
转载自stevenzuo.iteye.com/blog/2286065
今日推荐
周排行