输入:3
输出:123 132 213 231 312 321
解:
public class Main {
public static void fun(int n, int[] a, int cur) {
if (cur == n) {
for (int i = 0; i < n; i++)
System.out.print(a[i]);
System.out.println();
} else {
for (int i = 1; i <= n; i++) {
boolean ok = true;
for (int j = 0; j < cur; j++) {
if (a[j] == i)
ok = false;
}
if (ok) {
a[cur] = i;
fun(n, a, cur + 1);
}
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
fun(n, a, 0);
}
}