提交时间:2023-11-04 09:19:26

运行 ID: 108694

#include<bits/stdc++.h> using namespace std; int n,a[10],b[10],s; void dfs(int step) { if(step==n) { for(int i=1;i<=n;i++) cout<<a[i]; cout<<'\n'; s++; } for(int i=1;i<=n;i++) { if(!b[i]) { a[step+1]=i; b[i]=1; dfs(step+1); b[i]=0; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin>>n; dfs(0); cout<<s; return 0; }