Cod sursa(job #2449669)
Utilizator | Data | 20 august 2019 13:59:01 | |
---|---|---|---|
Problema | Combinari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdio>
using namespace std;
int sol[19], n, k;
void pick(int pos, int need) {
if (pos == n + 1) {
for (int j = 1; j <= k; j++)
printf("%d ", sol[j]);
printf("\n");
return;
}
if (need) {
sol[k + 1 - need] = pos;
pick(pos + 1, need - 1);
}
if (n - pos >= need)
pick(pos + 1, need);
}
int main() {
freopen ("combinari.in", "r", stdin);
freopen ("combinari.out", "w", stdout);
scanf("%d %d", &n, &k);
pick(1, k);
return 0;
}