next_permutation用法

当需要对一个序列中的元素进行全排列,可以使用该函数。
bool next_permutation(BidirectionlIterator first,BidirectionalIterator last);
包含于头文件

int a[]={1,2,3,4,5};
//产生所有下一组合,时间复杂度为n!,速度较慢
next_permutation(a,a+5);
prev_permutation(a,a+5);//上一组合

函数用法示例:
给一个数n,m
n表示一个从1,2,3,4…n的数列
m表示其第m个全排列

我的思路就是直接while m-1次next——permutation

ac代码:
这里写图片描述

如果对全排列不是很懂的..可以直接用这个函数水..

猜你喜欢

转载自blog.csdn.net/qq_39936389/article/details/82633059