您的位置:首页 > 编程语言 > C语言/C++

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()));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: