用法

字典序全排列

可以发现函数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. tkinter内嵌Matplotlib系列(一)之解读官网教材

    目录 目录 前言 (一)小目标 1.首页卷面: 2.绘制一条函数曲线: 3.绘制多条曲线: (二)官方教材 1.对GUI框架的支持: 2.内嵌于tkinter的说明文档: (三)对官方教程的解读 目录 ...

  2. February 4th, 2018 Week 6th Sunday

    Hope clouds observation. 心怀希望会蒙蔽双眼,影响判断. Almost every of us thinks we would be the master of our liv ...

  3. Weblogic读不到Word文件

    之前遇到一导出word文件的需求,我的做法是把对应导出内容放到一个word文件中,把其中变化的内容作为变量,然后把该word文件放在WEB-INF目录下用来作为模板.在导出时通过ServletCont ...

  4. Tronado自定义Form组件

    Tronado自定义Form组件 一.获取类里面的静态属性以及动态属性的方法 方式一: # ===========方式一================ class Foo(object): user ...

  5. UVA1599-Ideal Path(BFS进阶)

    Problem UVA1599-Ideal Path Time Limit: 3000 mSec Problem Description New labyrinth attraction is ope ...

  6. [Noi2002]Savage(欧几里得拓展)

    题意:在一个岛上,有n个野人.这些人开始住在c号洞穴,每一年走p个洞,而且他的生命有L年.问如果岛上的洞穴为一个圈,那么这个圈至少有多少个,才能使他们每年都不在同一个洞穴里. 分析:先假设一种简单的情 ...

  7. Arduino IDE for ESP8266 项目(2)wifi扫描

    #include "ESP8266WiFi.h" void setup() { Serial.begin(115200); //设定WiFi为STA模式,如果先前已连接上AP,则与 ...

  8. usb-cam (2)摄像机标定

    http://blog.csdn.net/heyijia0327/article/details/43538695 官方也给出了单目的标定教程和双目视觉的标定教程.本教程基于usb_cam  pack ...

  9. go标准库的学习-crypto/md5

    参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/md5" md5包实现了MD5哈希算法,参见RFC 1321. Con ...

  10. MetaMask/metamask-extension/mascara 的运行实现

    https://github.com/MetaMask/metamask-extension/tree/develop/mascara 找了很多个实例,基本上很少是不使用线上钱包的,只有metamas ...