Pagini recente » Cod sursa (job #82587) | Cod sursa (job #449024) | Cod sursa (job #1732520) | Cod sursa (job #1768348) | Cod sursa (job #2244525)
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <assert.h>
#include <queue>
#include <chrono>
#include <memory>
using LL = long long;
using ULL = int long long;
const std::string _problemName = "combinari";
namespace std {
std::ifstream fin(_problemName + ".in");
std::ofstream fout(_problemName + ".out");
}
#define USE_FILES
#ifdef USE_FILES
#define cin fin
#define cout fout
#endif
class Generator {
public:
Generator(int n, int k) : n_(n), k_(k), current_(k) {}
void generate() {
generateImpl(0);
}
private:
void output() {
for (auto i : current_) {
std::cout << i + 1 << ' ';
}
std::cout << '\n';
}
void generateImpl(int pos) {
if (pos >= k_) {
output();
return;
}
int firstChoice = (pos == 0) ? 0 : (current_[pos - 1] + 1);
for (int choice = firstChoice; choice < n_; ++choice) {
current_[pos] = choice;
generateImpl(pos + 1);
}
}
int n_;
int k_;
std::vector<int> current_;
};
int main() {
int n, k;
std::cin >> n >> k;
Generator(n, k).generate();
return 0;
}