STL里面的next_permutation求字典序排列问题
来源:互联网 发布:数据整合平台 编辑:程序博客网 时间:2024/05/16 06:39
next_permutation函数的实现原理:
在当前序列中,从尾端往前寻找两个相邻元素,前一个记为*i,后一个记为*ii,并且满足*i < *ii。然后再从尾端寻找另一个元素*j,如果满足*i < *j,即将第i个元素与第j个元素对调,并将第ii个元素之后(包括ii)的所有元素颠倒排序,即求出下一个序列了。
#include<cstdio>#include<algorithm>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include<string>#include<map>#define INF 99999999#define LL long long#define maxn 1005using namespace std;bool used[maxn];int perm[maxn];void permutation1(int pos,int n){if(pos==n){return ;}for(int i=0;i<n;i++){if(!used[i]){perm[pos]=i;used[i]=true;permutation1(pos+1,n);used[i]=false;}}return ;}int perm2[maxn];void permutation2(int n){for(int i=0;i<n;i++){perm2[i]=i;}do{for(int i=0;i<n;i++)cout << perm2[i] << ' ';cout << endl;}while(next_permutation(perm2,perm2+n));cout << endl;return ;}int main(){permutation2(4);return 0;}
阅读全文
0 0
- STL里面的next_permutation求字典序排列问题
- 标准库——STL里面的全排列:next_permutation()
- 生成字典序排列(C++ STL) next_permutation函数
- 字典序排列- STL next_permutation、DFS(深度优先搜索)
- STL之 next_permutation函数{(全排列)按字典序!!!!!}
- next_permutation函数 字典序排列
- STL的排列算法next_permutation
- 全排列问题的STL用法(next_permutation类)
- 全排列问题的STL用法(next_permutation类)
- STL中用next_permutation解决排列问题
- STL 中 next_permutation 的全排列思路
- STL next_permutation 全排列
- [STL]next_permutation全排列
- 全排列(STL next_permutation)
- next_permutation求下一个排列的原理
- 排列的字典序问题
- 排列的字典序问题
- 排列的字典序问题
- java底层知识
- Linux中DHCP服务器配置
- 4. Running Student
- Office远程代码执行漏洞POC样本分析(CVE-2017-11882)
- 11 H5上实现超声波测距模块的设备驱动
- STL里面的next_permutation求字典序排列问题
- 《时代》17年十大电子设备:iPhone X登榜
- leetcode解题方案--034--Search for a Range
- 关于Hibernate中的级联操作以及懒加载
- Windows 7 下 安装 mysql-5.7.20-win32.zip 教程
- 进程和线程
- 京东商城分类实现
- Centos7更换yum源
- Navicat工具导出mySQL数据库某个视图结构的.sql脚本