枚举排列

来源:互联网 发布:淘宝认证后怎么开店 编辑:程序博客网 时间:2024/06/02 16:02
/*利用STL中的next_permutation枚举排列*/#include <iostream>#include <algorithm>using namespace std;int main(){    int n, s[10];    int cnt = 0;    //计数共有多少种排列组合    cin >> n;    for(int i = 0; i < n; i++)        cin >> s[i];    sort(s, s + n);    do {        for(int i = 0; i < n; i++)            cout << s[i] << " " ;        cout << endl;        cnt++;    } while(next_permutation(s, s + n));    cout << cnt << endl;    return 0;}
0 0