#include <iostream>
#include <algorithm>
#include <vector> int main() {
int n, r;
n = ;
r = ; std::vector<bool> v(n);
std::fill(v.end() - r, v.end(), true);
std::vector< std::vector<int> > sequence_vector; do {
std::vector<int> sequence;
for (int i = ; i < n; ++i) {
if (v[i]) {
std::cout << (i + ) << " ";
sequence.push_back(i+);
}
}
std::cout << "\n";
sequence_vector.push_back(sequence);
} while (std::next_permutation(v.begin(), v.end())); std::cout<<"from vector"<<std::endl; std::vector<int>::iterator iterator_sequence;
std::vector< std::vector<int> >::iterator iterator_sequence_vector;
for(iterator_sequence_vector = sequence_vector.begin();
iterator_sequence_vector != sequence_vector.end(); iterator_sequence_vector++){
for (iterator_sequence = (*iterator_sequence_vector).begin();
iterator_sequence != (*iterator_sequence_vector).end(); iterator_sequence++){
std::cout<<*iterator_sequence<<" ";
}
std::cout<<std::endl;
} return ;
}

c++ combination by next_permutation的更多相关文章

  1. [算法]——全排列(Permutation)以及next_permutation

    排列(Arrangement),简单讲是从N个不同元素中取出M个,按照一定顺序排成一列,通常用A(M,N)表示.当M=N时,称为全排列(Permutation).从数学角度讲,全排列的个数A(N,N) ...

  2. 全排列函数(next_permutation())

    平常需要全排列的时候,一般都是dfs然后字符串匹配啥的……今天看题解的时候突然发现了这个神器. next_permutation()函数在c++的algorithm库里,作用是传入一个数组,输出这个数 ...

  3. [LeetCode] Combination Sum IV 组合之和之四

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  4. [LeetCode] Combination Sum III 组合之和之三

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  5. [LeetCode] Combination Sum II 组合之和之二

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  6. [LeetCode] Combination Sum 组合之和

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  7. 55. 2种方法求字符串的组合[string combination]

    [本文链接] http://www.cnblogs.com/hellogiser/p/string-combination.html [题目] 题目:输入一个字符串,输出该字符串中字符的所有组合.举个 ...

  8. 377. Combination Sum IV

    问题 Given an integer array with all positive numbers and no duplicates, find the number of possible c ...

  9. 关于全排列 next_permutation() 函数的用法

    这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...

随机推荐

  1. Multi-Thread 1: how to use synchronized

    1. synchronized If two threads are using the same function( here we use output to print out string) ...

  2. 2018.11.8 Error contacting service. It is probably not running.

    安装zookeeper-3.4.6的时候,启动正常没报错,但zkServer.sh status查看状态的时候却出现错误,如下: JMX enabled by default Using config ...

  3. ueditor1.2.6图片被压缩的解决办法

    修改文件路径: ueditor\dialogs\image\image.html 修改数值:

  4. P3909 异或之积

    P3909 异或之积 为什么叫做异或之积? 答曰:只要不关乎Alice和Bob就行 做完这道水题,感觉自己弱爆了. 一开始就要考虑暴力\(O(n^3)\)的优化. 然后就注意到了题目中的\(6\)为什 ...

  5. video object detection

    先说一下,我觉得近两年最好的工作吧.其他的,我就不介绍了,因为我懂得少. 微软的jifeng dai的工作. Deep Feature Flow   github: https://github.co ...

  6. Page 由于代码已经过优化或者本机框架位于调用堆栈之上

    Page.Response.Clear();            Page.Response.Write("<script type=\"text/javascript\& ...

  7. spring入门(七) spring mvc+mybatis+generator

    1.Mybatis-Generator下载 地址:https://github.com/mybatis/generator/releases 我使用的是 mybatis-generator-core- ...

  8. iOS之UIKeyboardType 11种键盘图片展示

    UIKeyboardTypeDefault      UIKeyboardTypeASCIICapable  ==  UIKeyboardTypeAlphabet      UIKeyboardTyp ...

  9. Spring知识点小结(一)

    一.Spring的简介 1.spring是一个full-stack轻量级开源框架    2.spring的两大核心        IoC: inverse of control  控制反转:反转是对象 ...

  10. 如何在match中使用正则表达式

    这是在实现搜索功能的时候遇到的一个问题,在搜索的场景中,会根据搜索框中输入的内容,匹配出包含搜索内容的部分.简单模拟还原使用场景: 首先定义一个遍历 value 用来接收输入的内容 var value ...