Pagini recente » Cod sursa (job #453794) | Cod sursa (job #423779) | Cod sursa (job #1764272) | Cod sursa (job #492424) | Cod sursa (job #1811785)
#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;
}
vector<string> all;
for (int mask = (1 << k) - 1; mask < (1 << n); mask = GetNextCombination(mask)) {
string current = "";
for (int aux = mask; aux; aux &= aux - 1) {
current = current + to_string(1 + logarithm[aux & -aux]) + " ";
}
all.emplace_back(current);
}
sort(begin(all), end(all));
for (const string& m_string : all) {
cout << m_string << '\n';
}
}