Pagini recente » Cod sursa (job #1287147) | Cod sursa (job #1822074) | Cod sursa (job #2494707) | Cod sursa (job #817974) | Cod sursa (job #1811794)
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;
void BackTrack(const int& n, const int& k, vector<int> stack, ostream& out) {
if (SZ(stack) == k + 1) {
for (const int& x : stack) {
if (x != 0) {
out << x << ' ';
}
}
out << '\n';
} else {
const int bound = n - k + SZ(stack) + 1;
for (int i = stack.back() + 1; i <= bound; i++) {
stack.emplace_back(i);
BackTrack(n, k, stack, out);
stack.pop_back();
}
}
}
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> stack(1, 0);
BackTrack(n, k, stack, cout);
}