51nod 1348【next_permutation】

来源:互联网 发布:sql insert into 语法 编辑:程序博客网 时间:2024/04/30 04:37

next_permutation的粗讲来自窝bin博客
两个重载函数,第二个带谓词参数_Comp,其中只带两个参数的版本,默认谓词函数为”小于”.
返回值:bool类型
分析next_permutation函数执行过程:
假设数列 d1,d2,d3,d4……
范围由[first,last)标记,调用next_permutation使数列逐次增大,这个递增过程按照字典序。
next_permutation在algorithm头文件里,可以用它来生成全排列。

#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N=10;char a[N];int main(){    int len;    scanf("%s",a);    len=strlen(a);    sort(a,a+len);    printf("%s\n",a);    while(next_permutation(a,a+len))        printf("%s\n",a);    return 0;}
0 0