Cod sursa(job #983813)

Utilizator cosmo0093Raduta Cosmin cosmo0093 Data 12 august 2013 19:33:36
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>
#include <vector>

void print(std::ostream& out, std::vector<int>& myV)
{
	for(std::vector<int>::iterator it = myV.begin(); it != myV.end(); it++)
		out << *it << ' ';
	out << '\n';
}

void bt(std::ostream& out, std::vector<int>& myV, int nV, int nC)
{
	if(myV.size() == nC)
	{
		print(out, myV);
		return;
	}
	int i;
	if(myV.empty()) i = 1;
	else i = myV.back() + 1;
	while(i <= nV)
	{
		myV.push_back(i);
		bt(out, myV, nV, nC);
		myV.pop_back();
		i++;
	}
}

int main()
{
	std::ifstream in("combinari.in");
	std::ofstream out("combinari.out");
	
	int nV, nC;
	
	in >> nV >> nC;
	
	std::vector<int> myV;
	
	bt(out, myV, nV, nC);
	return 0;
}