AcWing 842. 排列数字
原题链接
简单
可以算是dfs梦开始的地方了
import java.util.*;
public class Main {
static int n;
static int N = 10;
static int[] nums = new int[N];
static boolean[] st = new boolean[N];
private static void dfs(int u, int[] nums, boolean st[]) {
if (u == n) {
for (int i = 0; i < n; i++) System.out.print(nums[i] + " ");
System.out.println();
} else {
for (int i = 1; i <= n; i++) {
if (!st[i]) {
st[i] = true;
nums[u] = i;
dfs(u + 1, nums, st);
st[i] = false;
}
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
dfs(0, nums, st);
}
}
刚入,为什么我发不了说说