提交时间:2023-11-04 09:09:14
运行 ID: 108637
#include<bits/stdc++.h> using namespace std; #include <iostream> using namespace std; int a[11],b[11],n,counts; void dfs(int k){ if(k==n+1){ for(int i=1;i<=n;i++){ cout<<a[i]; } cout<<endl; counts++; return; } for(int i=1;i<=n;i++){ if(b[i]==0){ b[i]=1; a[k]=i; dfs(k+1); b[i]=0; } } } int main(){ //freopen("permutation.in","r",stdin); //freopen("permutation.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cin>>n; dfs(1); cout<<counts; return 0; }