提交时间:2023-10-28 08:35:23
运行 ID: 107707
#include<iostream> using namespace std; int a[30], n, cnt = 0; bool vis[30]; void f(int k){ if(k == n){ for(int i = 0; i < n; i++) cout << a[i]; cout << endl; cnt++; return; } for(int i = 1; i <= n; i++){ if(!vis[i]){ a[k] = i; vis[i] = true; f(k + 1); vis[i] = false; } } } int main(){ cin >> n; f(0); cout << cnt; return 0; }