Pagini recente » Cod sursa (job #3359827) | Cod sursa (job #3359824)
// https://infoarena.ro/problema/combinari
#include<fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int sol[19];
int main() {
int n, k;
fin >> n >> k;
int nivel = 1;
sol[0] = 1;
while(nivel >= 1) {
if(nivel == k + 1) {
for(int i = 1; i <= k; i++) {
fout << sol[i] << " ";
}
fout << "\n";
nivel--; // POP stiva
} else {
sol[nivel]++;
if(sol[nivel] <= n) {
sol[nivel + 1] = sol[nivel];
nivel++; // PUSH stiva
} else {
nivel--; // POP stiva
}
}
}
return 0;
}