zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C++中全排列算法函数next_permutation的使用方法

C++方法算法 函数 排列 Next Permutation 使用
2023-09-11 14:19:01 时间

首先,先看对next_permutation函数的解释: http://www.cplusplus.com/reference/algorithm/next_permutation/?kw=next_permutation

 

从中可以看出,全排列的第一个序列为从小到大排好序的序列,最后一个序列为从大到小排好序的序列。

使用next_permutation函数的注意点:

在使用此函数之前,必须先对原序列使用sort进行排序,不然则不能获得其全部的全排列。