Pagini recente » Borderou de evaluare (job #3299921) | Borderou de evaluare (job #2413968) | Borderou de evaluare (job #3250011) | Borderou de evaluare (job #1077410) | Cod sursa (job #3326537)
#include <bits/stdc++.h>
using namespace std;
int n, k;
array<int, 20> st;
bool validare_distincte(int nivel) {
for(int i = 1; i < nivel; ++i) {
if(st[i] == st[nivel]) {
return false;
}
}
return true;
}
bool check_increase(int nivel) {
for(int i = 1; i < nivel; ++i) {
if(st[i] > st[i+1]) {
return false;
}
}
return true;
}
void back(int nivel) {
for(int i = 1; i <= n; ++i) {
st[nivel] = i;
if(validare_distincte(nivel) && check_increase(nivel)) {
if(nivel == k) {
for(int j = 1; j <= k; ++j) cout << st[j] << ' ';
cout << '\n';
} else back(nivel + 1);
}
}
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifndef LOCAL
freopen("combinari.in", "r", stdin);
freopen("combinari.out", "w", stdout);
#endif
cin >> n >> k;
back(1);
return 0;
}