枚举排列
Cworld2017
这个作者很懒,什么都没留下…
展开
-
生成1~n的排列
先生成以一开头的排列,#include using namespace std;int a[100];void print_per(int n,int a[],int cur){ if(cur==n) { for(int i=0;i<n;i++)cout<<a[i]; cout<<endl; } else {原创 2017-08-07 11:08:51 · 374 阅读 · 0 评论 -
生成可重集的排列
输入数组P,按字典序输出p各元素的全排列#include using namespace std;int a[100];void print_per(int n,int a[],int p[],int cur){ if(cur==n) { for(int i=0;i<n;i++)cout<<a[i]; cout<<endl; }原创 2017-08-07 11:46:54 · 330 阅读 · 0 评论 -
next_permutation()的用法,与作用
在枚举排列中,用stl中的nextpermutation()函数无论输入的序列中是否都是重复元素#include #include #include using namespace std;int p[100];int main(){ int n;cin>>n; for(int i=0;i>p[i]; sort(p,p+n); do {原创 2017-08-07 11:59:42 · 1306 阅读 · 0 评论