首页 > 其他 > 详细

全排列(next_permutation)

时间:2016-09-01 23:00:54      阅读:248      评论:0      收藏:0      [点我收藏+]

next_permutation函数既可用于非重排列也可用于重排列;

#include <bits/stdc++.h>
#define MAXN 200000+10
#define ll long long
using namespace std;

int a[MAXN];

int main(void)
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    cin >> a[i];
    sort(a, a+n);
    do
    {
        for(int i=0; i<n; i++)
        cout << a[i] << " ";
        cout << endl;
    }while(next_permutation(a, a+n));
    return 0;
}

全排列(next_permutation)

原文:http://www.cnblogs.com/geloutingyu/p/5831523.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!