#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. HDU 5805

    题意: 退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列.他在纸上随便写了一个长度为 nn 的数列,他又根据心情随便删了一个数,这样他得到了一个新的数列,然后 ...

  2. HDU 5536 Chip Factory 【01字典树删除】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...

  3. 【luogu P4462 [CQOI2018]异或序列】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4462 ax+ax-1+...+ay = cntx+cnty 这样把一段序列变成两段相加跑莫队. #inclu ...

  4. tomcat的下载和启动

    1.下载和解压 把下载好的压缩包解压,放到想刚的目录里 看一下目录: 目录介绍: 2. 启动和访问 启动步骤: 如果startup.bat 双击执行脚本一闪而过,解决方法: 第一可能是:没有配置JAV ...

  5. 写到 HTML 文档

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  6. Angularjs实例4

    <!DOCTYPE html><html lang="zh-cn" ng-app=""><head><meta htt ...

  7. html基础用法(下)

    设计表格: <html> <head> <title>表格</title> <meta charset="utf-8" /&g ...

  8. Java基础——XML复习

    XML                 SGML : 标准通用置标语言    Standard Generailzed    Markup Language XML                   ...

  9. Oracle EM12c 安装

    EM12c系统由下列组件构成: 1.Oracle Management Agent(管理代理) 2.Oracle Management Service(管理服务) 3.Oracle Managemen ...

  10. 为什么你的 App 没人用?请按这8条逐一对照

    为什么你的 App 没人用?请按这8条逐一对照 Kamo Asatryan 可能是这个世界上关注创新生态系统最多的一些人之一,他观察过数百个移动端 App,深入思考过它们的运行机制,并为它们的快速增长 ...