package practice;
import java.util.Scanner;
/*
* liệt kê hoán vị của n phần tử
*/
public class SinhHoanVi {
static int n;
static int[] arr;
static int[] visit;
static void result() {
for (int i = 1; i <= n; i++) {
System.out.print(arr[i] + ” “);
}
System.out.println();
}
static void Try(int index) {
for (int j = 1; j <= n; j++) {
if(visit[j] == 0) {
arr[index] = j;
visit[j] = 1;
if(index == n) result();
else Try(index + 1);
visit[j] = 0;
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
arr = new int[n + 1];
visit = new int[n + 1];
// có vẻ khởi tạo cấu hình đầu tiên hay không thì kết quả chạy vẫn thế
// for(int i=1; i<=n; i++) {
// arr[i] = i;
// }
Try(1);
}
}