#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
template <typename T>
void Combination(const std::vector<T>& v, std::size_t count)
{
assert(count <= v.size());
std::vector<bool> bitset(v.size() - count, 0);
bitset.resize(v.size(), 1);
do {
for (std::size_t i = 0; i != v.size(); ++i) {
if (bitset[i]) {
std::cout << v[i] << " ";
}
}
std::cout << std::endl;
} while (std::next_permutation(bitset.begin(), bitset.end()));
}
int main() {
const std::vector<int> v = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Combination(v, 3);
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgp2b2lkIENvbWJpbmF0aW9uKGNvbnN0IHN0ZDo6dmVjdG9yPFQ+JiB2LCBzdGQ6OnNpemVfdCBjb3VudCkKewogICAgYXNzZXJ0KGNvdW50IDw9IHYuc2l6ZSgpKTsKICAgIHN0ZDo6dmVjdG9yPGJvb2w+IGJpdHNldCh2LnNpemUoKSAtIGNvdW50LCAwKTsKICAgIGJpdHNldC5yZXNpemUodi5zaXplKCksIDEpOwogCiAgICBkbyB7CiAgICAgICAgZm9yIChzdGQ6OnNpemVfdCBpID0gMDsgaSAhPSB2LnNpemUoKTsgKytpKSB7CiAgICAgICAgICAgIGlmIChiaXRzZXRbaV0pIHsKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCB2W2ldIDw8ICIgIjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwogICAgfSB3aGlsZSAoc3RkOjpuZXh0X3Blcm11dGF0aW9uKGJpdHNldC5iZWdpbigpLCBiaXRzZXQuZW5kKCkpKTsKfQoKaW50IG1haW4oKSB7Cgljb25zdCBzdGQ6OnZlY3RvcjxpbnQ+IHYgPSB7MCwgMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOX07CgkKCUNvbWJpbmF0aW9uKHYsIDMpOwp9Cg==