C++ 11 : create all possible k combinations of n items
2016-07-13 23:07
519 查看
#include <iostream> #include <algorithm> #include <vector> main () { int nn = 5; int r = 3; std::vector<int> v_real = { 1, 2, 3, 4, 5 }; for (int r = 1; r <= nn; r++) { std::vector<bool> v(nn); std::fill(v.begin(), v.begin() + r, true); do { for (int i = 0; i < nn; ++i) { if (v[i]) { std::cout << v_real[i] << " "; } } std::cout << "\n"; } while (std::prev_permutation(v.begin(), v.end())); } }
相关文章推荐
- 解决VS 2010/2012 C++ 生成的exe在非编译环境电脑中缺失dll的方法
- 将类封装成dll/lib的方法
- 编译器 内置宏 并且 支持不同c++标准,__cplusplus不同
- c++ static 变量的使用和用途
- 一起学习c++11——c++11中的新语法
- NwCreate之创建nwc文件
- keybd_event常量符号 含义
- 模拟键盘输入字符串的C++类
- 模拟键盘向当前光标处发送字符串
- 分割字符串
- 获取多个同名窗口的句柄
- 基于C语言sprintf函数的深入理解
- 提高项目31.4-读入一个C++程序,整理其格式,使其按规范排版
- 最小化所有窗口(模拟显示桌面)
- EnumWindows 传递自定义参数实例
- 生成rdp文件中的密码字串
- 获取Windows版本
- c语言字符串和c语言float的问题解答
- MFC简单线程_两个线程比较
- 正确读取REG_DWORD键值