public class Liang {
public static char[] str = {'a','b','c','d','e','f'};
public static boolean[] visit = new boolean[str.length];
public static char[] result = new char[str.length];
public static int total = 0;
public static void main(String[] args) {
total = 0;
Arrays.fill(visit, false);
dfs(0);
System.out.println(total);
}
public static void dfs(int level){
if( level == str.length){
show();
total++;
return;
}
for(int i = 0 ; i < str.length; i++){
if(!visit[i]){
visit[i] = true;
result[level] = str[i];
visit[i] = false;
dfs(level+1);
//visit[i] = false;
}
}
return;
}
public static void show(){
for(int i = 0; i < result.length; i++){
System.out.print(result[i]);
}
System.out.println();
}
}
对n个不同字母的全排列
最新推荐文章于 2022-12-20 15:20:21 发布