提交时间:2025-11-15 13:23:03
运行 ID: 361085
#include<bits/stdc++.h> using namespace std; int n; int p[10]; bool a[10]; void hsg(int x){ if(x==n){ for(int i=0;i<n;i++){ cout<<p[i]<<" "; } puts(" ");//换行 return ; } for(int i=1;i<=n;i++){ if(!a[i]){ a[i]=true; p[x]=i; //枚举位置上数字的可能性 hsg(x+1); //下一层 a[i]=false; //恢复现场 } } } int main(){ cin>>n; hsg(0); return 0; }