next_permutation函数初识
来源:互联网 发布:深圳淘宝产品拍摄 编辑:程序博客网 时间:2024/06/05 13:39
#include <iostream>#define MAX_M 10#define MAX_N 10using namespace std;bool used[MAX_N];int perm[MAX_M];// 生成{1,2,3,4,....,n-1}的n!种排列void permutation1(int pos,int n){ if (pos == n){ cout << n << ' '; return ; } // 针对perm的第pos个位置,究竟使用0~n-1中的哪个循环 for (int i = 0;i < n;i ++){ if (!used[i]){ perm[pos] = i; // i已经被使用过了,所以把标志设置为true used[i] = true; permutation1(pos + 1,n); // 返回之后把标志复位 used[i] = false; } } return ;}#include <algorithm>// 即使有重复元素也会生成所有的排列// next_permutation是按照字典序来生成下一个排列的int perm2[MAX_N];void permutation2(int n){ for (int i = 0;i < n;i ++) perm2[i] = i; do { cout << n << ' '; } while (next_permutation(perm2,perm2 + n)); // 所以排列都生成后,next_permutation会返回false return ;}int main(){ permutation1(7,10); // 生成 10!/7! permutation2(8); // 生成8!}
阅读全文
0 0
- next_permutation函数初识
- next_permutation函数
- next_permutation函数
- next_permutation()函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- 写在开始
- mask rcnn源码模型踩坑(__reduce_cython__)指南(MxNet)
- 对seo与sem的全方位立体比较
- 备忘录
- hdu1863 (最小生成树)
- next_permutation函数初识
- 算法时间复杂度
- Javascript中字符串相关常用的使用方法总结
- Ansible playbook简介与配置
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法 java.lang.ClassNotFoundException: com.
- c++:error qualification in declaration of '....'
- 单节点Rancher Server v1.6.10版升级到v1.6.12版实验(上)
- mybatis官网参考文档-XML配置_settings(版本: 3.4.6-SNAPSHOT)
- 项目svn从一个地址换到了另一个地址, 现在需要把项目关联到另一个svn地址上