24 lines
495 B
C++
24 lines
495 B
C++
#include <algorithm>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
void comb(int N, int K)
|
|
{
|
|
std::string bitmask(K, 1); // K leading 1's
|
|
bitmask.resize(N, 0); // N-K trailing 0's
|
|
|
|
// print integers and permute bitmask
|
|
do {
|
|
for (int i = 0; i < N; ++i) // [0..N-1] integers
|
|
{
|
|
if (bitmask[i]) std::cout << " " << i;
|
|
}
|
|
std::cout << std::endl;
|
|
} while (std::prev_permutation(bitmask.begin(), bitmask.end()));
|
|
}
|
|
|
|
int main()
|
|
{
|
|
comb(5, 3);
|
|
}
|