枚举所有排列-STL中的next_permutation

枚举排列的常见方法有两种 一种是递归枚举 另一种是STL中的next_permutation

//枚举所有排列的另一种方法就是从字典序最小排列开始,不停的调用"求下一个排列"的过程 
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,p[10];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%d",&p[i]);
    sort(p,p+n);//得到最小排列
    do{
        for(int i=0;i<n;i++)
        printf("%d ",p[i]);
        printf("
"); 
    } while(next_permutation(p,p+n));
    return 0;
    
}

原文地址:https://www.cnblogs.com/is-Tina/p/7470493.html