next_permutation 函数

STL的next_permutation函数可以求出某个特定序列的下一个排列,当然,如果对一个给定序列,排序之后可以轻松求出全排列......

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<map>
 7 #include<set>
 8 #include<vector>
 9 #include<sstream>
10 using namespace std;
11 #define ll long long
12 const int inf=99999999;
13 const int mod=1e9+7;
14 //const int maxn=;
15 int num[100];
16 int main()
17 {
18     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
19    
20     int n;
21     cin>>n;
22     
23     for(int i=0;i<n;i++)
24         cin>>num[i];
25         
26     sort(num,num+n);
27     
28     cout<<"全排列 :"<<endl; 
29     do
30     {
31         for(int i=0;i<n-1;i++)
32             cout<<num[i]<<" ";
33         cout<<num[n-1]<<endl;
34     }
35     while(next_permutation(num,num+n));
36     
37     return 0;
38 }

 

转载于:https://www.cnblogs.com/xwl3109377858/p/10986717.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值