Cod sursa(job #1382348)

Utilizator gabi.cristacheGabi Cristache gabi.cristache Data 8 martie 2015 21:15:55
Problema Combinari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <vector>
#include <fstream>

std::ifstream fin("combinari.in");
std::ofstream fout("combinari.out");

std::vector<int> v(18);
int N, K;

bool isValid(int k) {
	for (int i = 0; i < k; ++i)
		if (v[i] == v[k])
			return false;
	return true;
}

void bk(int k) {
	for (int i = 1; i <= N; ++i) {
		v[k] = i;

		if (isValid(k)) {
			if (k == K - 1) {
				for (int j = 0; j <= k; ++j) {
					fout << v[j] << ' ';
				}
				fout << '\n';
			} else {
				bk(k + 1);
			}
		}
	}
}

int main() {
	fin >> N >> K;

	bk(0);

	return 0;
}