Cod sursa(job #2499395)

Utilizator radustn92Radu Stancu radustn92 Data 26 noiembrie 2019 00:17:54
Problema Combinari Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cstdio>
#include <vector>
using namespace std;

int N;
vector<int> currentSol;

void consume() {
	for (auto& value : currentSol) {
		printf("%d ", value);
	}
	printf("\n");
}

void back(int remainingElems) {
	if (remainingElems == 0) {
		consume();
		return;
	}

	int start = currentSol.empty() ? 0 : currentSol.back();
	for (int nextElem = start + 1; nextElem <= N; nextElem++) {
		currentSol.push_back(nextElem);
		back(remainingElems - 1);
		currentSol.pop_back();
	}
}

int main() {
	freopen("combinari.in", "r", stdin);
	freopen("combinari.out", "w", stdout);

	int N, K;
	scanf("%d%d", &N, &K);
	currentSol.reserve(N);
	back(K);
	return 0;
}