提交时间:2023-11-04 09:06:34
运行 ID: 108604
#include<bits/stdc++.h> using namespace std; int n,ans,a[10]; bool b[10]; void dfs(int depth){ if(depth>n){ for(int i=1;i<=n;i++){ printf("%d",a[i]); } printf("\n"); ans++; return; } for(int i=1;i<=n;i++){ if(!b[i]){ b[i]=1; a[depth]=i; dfs(depth+1); b[i]=0; } } return; } int main(){ //freopen("permutation.in","r",stdin); //freopen("permutation.out","w",stdout); cin>>n; dfs(1); cout<<ans; return 0; }