Pagini recente » Cod sursa (job #1899394) | Cod sursa (job #2907303) | Cod sursa (job #3348305) | Cod sursa (job #2471545) | Cod sursa (job #3327018)
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> st(20);
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) {
if(nivel > 1 && st[nivel-1] >= st[nivel])
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;
}