#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
a[i]=i;
do
{
for(int i=;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}while(next_permutation(a+,a+n+));
return ;
}
时间限制: 1 s
空间限制: 128000 KB
题目描述 Description
给出一个n, 请输出n的所有全排列
输入描述 Input Description
读入仅一个整数n (1<=n<=10)
输出描述 Output Description
一共n!行,每行n个用空格隔开的数,表示n的一个全排列。并且按全排列的字典序输出。
样例输入 Sample Input
3
样例输出 Sample Output
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1