AcWing 842. 排列数字
原题链接
简单
作者:
STU756
,
2021-02-07 02:08:23
,
所有人可见
,
阅读 341
import java.util.*;
public class Main{
static int n;
static int[] a = new int[10];
static int[] path = new int[10];
static boolean[] st = new boolean[10];
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;
}
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
n = s.nextInt();
dfs(0);
}
}