用法

字典序全排列

可以发现函数next_permutation()是按照字典序产生排列的,并且是从数组中当前的字典序开始依次增大直至到最大字典序。

代码

#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main(){
int n;
int a[10];
while(cin>>n){
int i;
for(i=0;i<n;i++) cin>>a[i];
cout<<endl;
//sort(a,a+n);
do{
for(i=0;i<n;i++) cout<<a[i]<<' ';
cout<<endl;
}while(next_permutation(a,a+n));
}
return 0;
}

STL next_permutation()的更多相关文章

  1. 打印全排列和stl::next_permutation

    打印全排列是个有点挑战的编程问题.STL提供了stl::next_permutation完美的攻克了这个问题. 可是,假设不看stl::next_permutation,尝试自己解决,怎么做? 非常自 ...

  2. STL next_permutation 算法原理和自行实现

    目标 STL中的next_permutation 函数和 prev_permutation 两个函数提供了对于一个特定排列P,求出其后一个排列P+1和前一个排列P-1的功能. 这里我们以next_pe ...

  3. STL next_permutation 算法原理和实现

    转载自:https://www.cnblogs.com/luruiyuan/p/5914909.html 目标 STL中的next_permutation 函数和 prev_permutation 两 ...

  4. STL next_permutation和prev_permutation函数

    利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...

  5. hdu1716排列2(stl:next_permutation+优先队列)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  6. STL - next_permutation 全排列函数

    学习: http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/deta ...

  7. STL next_permutation(a,a+n) 生成一个序列的全排列。满足可重集。

    /** 题目: 链接: 题意: 思路: */ #include <iostream> #include <cstdio> #include <vector> #in ...

  8. POJ 1833 排列【STL/next_permutation】

    题目描述: 大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 ...

  9. C++ STL, next_permutation用法。

    next_permutation 将按字母表顺序生成给定序列的下一个较大的序列,直到整个序列为 #include"iostream" #include"algorithm ...

随机推荐

  1. Python基础知识:字典

    1.字典中键-值为一对,keys()返回一个列表,包含字典中所有键,values()返回所有值 favorite_languages ={ 'jack':"python", 'al ...

  2. 【PAT】B1082 射击比赛(20 分)

    水提水题,直接贴代码啦 #include<cstdio> #include<algorithm> using namespace std; struct ppp{ int id ...

  3. django —— MVT模型

    转载----

  4. .net core 入坑经验 - 3、MVC Core之jQuery不能使用了?

    在View中添加了一段jQuery代码用来控制一个按钮的点击事件.发现运行时提示$对象没有定义,经过在浏览器右键查看源文件发现,script代码在引用jquery代码的上方,执行时jquery还未引入 ...

  5. 软件工程实践_结对Task2_ student_department_matching

    1. 给出结对成员的学号及姓名. 结对成员 031502506 陈龙江 031502529 王国超 click 2.首页给出项目的Github链接. github:传送门 3. 贴出你们生成的一组最& ...

  6. EasyUI tabs指定要显示的tab

    <div id="DivBox"  class="easyui-tabs" style="width: 100%; height: 100%;& ...

  7. HBase——强一致性详解

    Hbase是一个强一致性数据库,不是“最终一致性”数据库,官网给出的介绍: “Strongly consistent reads/writes: HBase is not an "event ...

  8. visual studio code前端插件及常用快捷键【转】

    通用插件 HTML Snippets 超级实用且初级的 H5代码片段以及提示 HTML CSS Support 让 html 标签上写class 智能提示当前项目所支持的样式新版已经支持scss文件检 ...

  9. 寒假训练——搜索 E - Bloxorz I

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

  10. Android之activity总结

    http://www.cnblogs.com/lyp3314/archive/2011/11/10/2244971.html 一.什么是activity Activity 是用户接口程序,原则上它会提 ...