public class 全组合 {
public static void main(String[] args) {
int[] a={3,2,7,6,7};
dfs(a, 0, new StringBuilder());
}
public static void dfs(int[] strs, int k, StringBuilder str) {
if(k>strs.length) {
return;
}
StringBuilder myStr;
for(int i = k; i < strs.length; i++) {
myStr = new StringBuilder(str);
myStr.append(strs[i]);
System.out.println(myStr.toString());
dfs(strs, i+1, myStr);
}
}
}
【DFS】JAVA全组合模板
最新推荐文章于 2024-08-28 22:04:30 发布