Pagini recente » Cod sursa (job #2078864) | Cod sursa (job #3245536) | Cod sursa (job #438879) | Cod sursa (job #1341443) | Cod sursa (job #2756676)
#include <fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
short n, k, combinations[19];
void generate_combinations(short current_value, short pos) {
if (pos == k + 1) {
for (short i = 1; i <= k; ++i) {
fout << combinations[i] << ' ';
}
fout << '\n';
}
for (short i = 1; i + current_value <= n; ++i) {
combinations[pos] = i + current_value;
generate_combinations(combinations[pos], pos + 1);
}
}
int main() {
fin >> n >> k;
generate_combinations(0, 1);
return 0;
}