#include <iostream>
#include <vector>
void generateSequences(int n, int k, std::vector<int>& currentSequence, int currentNumber) {
if (currentSequence.size() == k) {
for (int num : currentSequence) {
std::cout << num << " ";
}
std::cout << std::endl;
return;
}
for (int i = currentNumber - 1; i >= 1; --i) {
if (currentSequence.empty() || i < currentSequence.back()) {
currentSequence.push_back(i);
generateSequences(n, k, currentSequence, i);
currentSequence.pop_back();
}
}
}
int main() {
int n, k;
std::cin >> n >> k;
std::vector<int> currentSequence;
generateSequences(n, k, currentSequence, n + 1);
return 0;
}
int main() {
int n, k;
std::cin >> n >> k;
std::vector<int> currentSequence;
generateSequences(n, k, currentSequence, n); // Исправлено здесь
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
void f(vector<int> &t, int n, int pos = 0) {
if (pos >= t.size()) {
for (auto v: t) { cout << v << ' '; }
cout << '\n';
return;
}
for (t[pos] = t.size() - pos; t[pos] <= n; ++t[pos]) {
f(t, t[pos] - 1, pos + 1);
}
}
int main() {
int n, k;
cin >> n >> k;
vector<int> t(k);
f(t, n);
}
Входные данные
5 2
Результат работы
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4