AcWing 842. 排列数字-java
原题链接
简单
作者:
Susu
,
2020-01-26 21:40:49
,
所有人可见
,
阅读 637
import java.util.Scanner;
public class Main {
static int n;
static int[] path;
static boolean[] st;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
path = new int[n];
st = new boolean[n+1];
dfs(0);
}
public static void dfs(int u){
if(u==n){
for(int i=0;i<n;i++){
System.out.print(path[i]+" ");
}
System.out.println();
return;
}
for(int i=1;i<=n;i++){
if(!st[i]) {
path[u] = i;
st[i] = true;
dfs(u + 1);
st[i] = false;
}
}
}
}