全排列(next_permutation)

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

 1 #include <bits/stdc++.h>
 2 #define MAXN 200000+10
 3 #define ll long long
 4 using namespace std;
 5 
 6 int a[MAXN];
 7 
 8 int main(void)
 9 {
10     int n;
11     cin >> n;
12     for(int i=0; i<n; i++)
13     cin >> a[i];
14     sort(a, a+n);
15     do
16     {
17         for(int i=0; i<n; i++)
18         cout << a[i] << " ";
19         cout << endl;
20     }while(next_permutation(a, a+n));
21     return 0;
22 }

 



posted @ 2016-09-01 22:03  geloutingyu  阅读(168)  评论(0编辑  收藏  举报