codevs 1294 全排列 next_permuntation

#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+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
const ll INF=1e18+10;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    a[i]=i;
    do
    {
        for(int i=1;i<n;i++)
        printf("%d ",a[i]);
        printf("%d
",a[n]);
    }while(next_permutation(a+1,a+n+1));
    return 0;
}

 

 时间限制: 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

原文地址:https://www.cnblogs.com/jhz033/p/5932464.html