include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N = 10;
int n;
int state[N];//状态,0表示没放数,1-n表示放了哪些数;
bool used[N];//true表示用过,false表示没用过;
void dfs(int u){
if(u > n)//边界
{
for(int i = 1; i <=n; i ++ )//打印方案
printf(“%d “, state[i]);
puts(“”);
return;
}
//依次枚举每个分支,即当前位置可以存哪些数
for(int i = 1; i <= n; i ++ )
if(!used[i])
{
state[u] = i;
used[i] = true;
dfs(u + 1);
state[u] = 0;
used[i] = false;
}
}
int main()
{
cin>>n;
dfs(1);
return 0;
}