c++ combination by next_permutation
#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的更多相关文章
- [算法]——全排列(Permutation)以及next_permutation
排列(Arrangement),简单讲是从N个不同元素中取出M个,按照一定顺序排成一列,通常用A(M,N)表示.当M=N时,称为全排列(Permutation).从数学角度讲,全排列的个数A(N,N) ...
- 全排列函数(next_permutation())
平常需要全排列的时候,一般都是dfs然后字符串匹配啥的……今天看题解的时候突然发现了这个神器. next_permutation()函数在c++的algorithm库里,作用是传入一个数组,输出这个数 ...
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- [LeetCode] Combination Sum III 组合之和之三
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- [LeetCode] Combination Sum II 组合之和之二
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- [LeetCode] Combination Sum 组合之和
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- 55. 2种方法求字符串的组合[string combination]
[本文链接] http://www.cnblogs.com/hellogiser/p/string-combination.html [题目] 题目:输入一个字符串,输出该字符串中字符的所有组合.举个 ...
- 377. Combination Sum IV
问题 Given an integer array with all positive numbers and no duplicates, find the number of possible c ...
- 关于全排列 next_permutation() 函数的用法
这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...
随机推荐
- python:生产者与消费者模型
1,生产者与消费者模型的矛盾在于数据供需的不平衡 import time import random from multiprocessing import Queue from multiproce ...
- NEUACM1132: Renew MST Quickly 增量最小生成树
题目链接:http://acm.neu.edu.cn/hustoj/problem.php?id=1132 和UVa11354很类似 题意: 原先有一棵树,每次加一条边,看最小生成树大小: 这个和增量 ...
- Css 截取字符串长度
.shortNameShow{ overflow:hidden; text-overflow:ellipsis; -o-text-overflow:ellipsis; white-space:nowr ...
- 【luogu P1801 黑匣子_NOI导刊2010提高(06)】 题解
题目链接:https://www.luogu.org/problemnew/show/P1801 替罪羊树吼啊! #include <cstdio> #include <cstrin ...
- Android学习笔记_73_授权过程
.需要申请App Key和App Secret.不同的开发平台有不同的接入方式,可以参考文档,然后将这两个值放进去. .通过OAuth类实现认证,它会自动跳转到认证界面,进行授权,成功之后需要处理回调 ...
- java中String、包装类、枚举类的引用传递
一般情况下,我们认为Java中了除了八种基本数据类型,其他都是对象,进行引用传递: 但是:String.包装类.枚举类作为参数传递后发现,没有达到引用传递的效果,很多人认为它是值传递! 首先,对象肯定 ...
- Oracle,Mysql,SQlserver生成实体映射之SqlSugarT4
官网:http://www.codeisbug.com 代码已上传GitHub:https://github.com/SeaLee02/sealee 本篇主要讲使用SqlSugar包进行Model生成 ...
- ROUND()和TRUNC()函数
ROUND(number[,decimals]) 其中:number 待做截取处理的数值: decimals 指明需保留小数点后面的位数,可选项.需要注意的是,和trunc函数不同,对截取的数字要四舍 ...
- JavaScript-语法专题
一.数据类型的转换 概述 JavaScript是一种动态语言,变量没有类型限制,可以随时赋予任意值 强制转换:主要是值Number(),String(),Boolean三个函数 Number函数,可以 ...
- C#实现文件上传以及文件下载
public ActionResult Upload() { // var pathUrl = "http://" + Request.Url.Authority; var fil ...