提交时间:2023-11-04 09:09:32
运行 ID: 108641
#include<iostream> #include<stdio.h> using namespace std; int a[10], n, ans = 0; bool b[10]; void f(int x){ if(x == n){ for(int i = 0; i < n; i++) cout << a[i]; cout << endl; ans++; return; } for(int i = 1; i <= n; i++){ if(!b[i]){ b[i] = true; a[x] = i; f(x + 1); b[i] = false; } } } int main(){ // freopen("permutation.in", "r", stdin); // freopen("permutation.out", "w", stdout); cin >> n; f(0); cout << ans; return 0; }