Pagini recente » Cod sursa (job #1385147) | Cod sursa (job #2099455) | Cod sursa (job #908731) | Cod sursa (job #2914244) | Cod sursa (job #1811779)
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;
int GetNextCombination(const int &x) {
const int y = (x | (x - 1)) + 1;
return y | ((((y & -y) / (x & -x)) >> 1) - 1);
}
int main() {
#ifdef INFOARENA
ifstream cin("combinari.in");
ofstream cout("combinari.out");
#endif
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, k; cin >> n >> k;
vector<int> logarithm(1 << n);
for (int i = 2; i < (1 << n); i++) {
logarithm[i] = logarithm[i / 2] + 1;
}
for (int mask = (1 << k) - 1; mask < (1 << n); mask = GetNextCombination(mask)) {
for (int aux = mask; aux; aux &= aux - 1) {
cout << 1 + logarithm[aux & -aux] << ' ';
}
cout << '\n';
}
}