关于next_permutation的用法
2013-08-21 15:44
337 查看
next_permutation是STL中的一个函数,头文件是#include<algorithm>,作用是生成全排列,默认是后一个比前一个大
例如aacc,生成全排列后为:acac acca caac caca ccaa ,根据ASCALL码的顺序排列,加上本身共6个!
函数模型:
bool next_permutation(first, last);
bool next_permutation(first,last,cmp); cmp为比较函数,自己定义即可。
CODE:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int len,count=0;
char s[20];
gets(s); //貌似不能用scanf("%c",s[i]),可用scanf("%s",s)直接输入
len=strlen(s);
sort(s,s+len);
while(next_permutation(s,s+len))
{
puts(s);//同理
count++;
}
printf("%d\n",count+1);
return 0;
}
更多更详细的介绍请进 http://www.cplusplus.com/reference/algorithm/next_permutation/
http://www.slyar.com/blog/stl_next_permutation.html
PS:现阶段只知道这么多,本人只是抛砖引玉,希望各位大神指点指点!!
例如aacc,生成全排列后为:acac acca caac caca ccaa ,根据ASCALL码的顺序排列,加上本身共6个!
函数模型:
bool next_permutation(first, last);
bool next_permutation(first,last,cmp); cmp为比较函数,自己定义即可。
CODE:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int len,count=0;
char s[20];
gets(s); //貌似不能用scanf("%c",s[i]),可用scanf("%s",s)直接输入
len=strlen(s);
sort(s,s+len);
while(next_permutation(s,s+len))
{
puts(s);//同理
count++;
}
printf("%d\n",count+1);
return 0;
}
更多更详细的介绍请进 http://www.cplusplus.com/reference/algorithm/next_permutation/
http://www.slyar.com/blog/stl_next_permutation.html
PS:现阶段只知道这么多,本人只是抛砖引玉,希望各位大神指点指点!!
相关文章推荐
- 关于全排列 next_permutation() 函数的用法
- 关于全排列 next_permutation() 函数的用法
- 关于全排列 next_permutation() 函数的用法
- HDU.1027 Ignatius and the Princess II【全排列:关于next_permutation问题】(3.14)
- next_permutation(,)用法
- next_permutation(排列组合)函数的用法
- (转载)关于next_permutation()
- next_permutation(,)用法
- C++ STL algorithm库中 next_permutation()用法 注意事项
- next_permutation()的用法,与作用
- next_permutation的思想和用法
- next_permutation用法 与 字典序
- 全排列 next_permutation 简单用法
- next_permutation(,)用法
- STL中next_permutation用法小结和小技巧总结与原理。
- 关于next_permutation
- 全排列next_permutation的用法(稍微有点改动)
- C++STL的next_permutation 的用法
- next_permutation 与 prev_permutation的用法 (全排列)
- HDU1716 排列2 next_permutation的用法