黑科技(next_permutation和prev_permutation)
来源:互联网 发布:南京行知实验幼儿园 编辑:程序博客网 时间:2024/04/30 05:35
关于数列的全排列问题:
如果我们要得到a[]={2,1,3}的全排列,我们可以有如下两种做法:
1、将数列排成升序:(1,2,3),如下写代码:
do{ cout << a[0] << " " << a[1] << " " << a[2] << endl;}while (next_permutation(a,a+3))
2、将数列排成降序:(3,2,1),如下写代码:
do{ cout << a[0] << " " << a[1] << " " << a[2] << endl;}while (prev_permutation(a,a+3))即可得到数列的全排列。
如果对vector<int> a进行全排列,则参数可以写成next_permutation(a.begin(),a.end())。
0 0
- 黑科技(next_permutation和prev_permutation)
- stl中的next_permutation和prev_permutation
- STL/next_permutation()和prev_permutation()函数
- next_permutation函数和prev_permutation函数
- next_permutation & prev_permutation
- next_permutation,prev_permutation
- next_permutation & prev_permutation
- STL源码学习----next_permutation和prev_permutation算法
- 排列函数 prev_permutation和next_permutation的使用
- STL全排列算法next_permutation和prev_permutation
- STL算法:prev_permutation和next_permutation的使用
- STL具体操作之next_permutation和prev_permutation函数
- STL之next_permutation和prev_permutation函数
- 【经典算法】STL之next_permutation和prev_permutation
- STL算法:prev_permutation和next_permutation的使用
- next_permutation和prev_permutation函数的用法
- STL prev_permutation&next_permutation
- next_permutation与prev_permutation
- 在无线互联的这些事连载二
- URAL 1715. Another Ball Killer (大模拟)
- u32、u16、u8 数据类型
- 大型网络游戏服务器的框架设计
- C语言的顺序表访问小代码
- 黑科技(next_permutation和prev_permutation)
- HBase的compact分析
- E 接口
- 大型网站架构演化
- Asp.net数据库链接
- linux权限控制机制
- PAT (Advanced Level) 1075. PAT Judge (25) PAT排名 结构体排序
- 磁盘IO的几种工作机制
- easyui 向后台传参出现缓存问题的可能原因以及解决办法