//借助两个数组,使用dfs输出全排列
import
java.util.Arrays; public class FullPermutation { private static int [] result;//存放全排列的结果 private static boolean [] visit;//定义一个标记数组 private static int total; //全排列的长度 private static void dfs(int count){ if(count==total){ System.out.println(Arrays.toString(result)); //return; } for(int i=0;i<total;i++){ if(visit[i]){ visit[i] = false; result[count] = i; dfs(count+1); visit[i] = true; } } } public static void main(String[] args) { total = 3;//以长度为5举例 result = new int[total]; visit = new boolean[total]; Arrays.fill(visit,true); dfs(0); } }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-07-26
  • 2022-12-23
  • 2021-05-17
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2021-04-16
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
相关资源
相似解决方案