STL next——permutation函数 求数列的全排列
来源:互联网 发布:数据预测方法 编辑:程序博客网 时间:2024/05/16 10:57
在C++的标准函数库STL中,next_permutation()函数用于求数列的全排列。
代码:
例子1(int型):int main(){int a[] = {3,1,2}; do{ cout << a[0] << " " << a[1] << " " << a[2] << endl; }while (next_permutation(a, a+3)); return 0; }输出:312/321因为原数列不是从最小字典排列开始。 所以要想得到所有全排列int a[] = {3,1,2}; 然后先排序为:a[] = {1,2,3};例子2(string型)int main(){string str; cin >> str; sort(str.begin(), str.end()); do{ cout << str << endl; }while (next_permutation(str.begin(), str.end())); return 0; }库中另一函数prev_permutation()与next_permutation()相反
0 0
- STL next——permutation函数 求数列的全排列
- 【poj】2718全排列next—permutation
- [LeetCode]—Next Permutation (全排列字典序)
- STL源码——排列生成算法(next-permutation、pre-permutation)
- 求数列的全排列(递归解法)
- 求任意数列的全排列
- Next Permutation下一个全排列序列
- 全排列,next-permutation 简单实现
- 51Nod 1384 全排列(next-permutation)
- LeetCode[31] Next Permutation 求下一个排列
- 求排列的stl函数
- 数据结构与算法[LeetCode]—Permutation Sequence 求n个数的全排列中第K个序列
- 回溯法——permutation、permutation II数组数字的全排列
- 求1—n的全排列
- 求字典序的下一个排列(对应lc的Next Permutation)
- POJ 3785 The Next Permutation 全排列字典序法
- Leetcode #31. Next Permutation 下一个全排列 解题报告
- 下一个排列(Next Permutation)
- c++函数中的默认参数
- python写代码实现list的deepcopy
- Qt之GUI学习笔记(十)----QFileDialog
- Android开源音视频播放器
- python
- STL next——permutation函数 求数列的全排列
- super();调用父类构造器
- 安装docker以及一些简单的使用
- 输入三个整数,按由小到大的顺序输出。
- 完数问题
- 分布式系统最终一致性的防护栏---幂等
- 【Java基础】关于异常
- iOS中pch文件的设置
- Android小菜鸟进阶之路