Cod sursa(job #235313)

Utilizator cvicentiuCiorbaru Vicentiu Marian cvicentiu Data 23 decembrie 2008 12:50:31
Problema Combinari Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
using namespace std;
int n,k;
int p;
int st[19];
fstream fin ("combinari.in",ios::in);
fstream fout("combinari.out",ios::out);

void citire(void){
	fin>>n>>k;
}

int solutie(){
	if (st[p]<=n && p==k)
		return 1;
	return 0;
}

int as(){
	if (p<k && st[p]<=(n-p+1))
		return 1;
	return 0;
}

void print_it(){
	for (int i=1;i<=k;i++)
		fout<<st[i]<<" ";
		fout<<endl;
}

void bt(){
	
	p=1;
	st[p]=1;
	while (st[1]<=(n-k)+1){
		if (solutie()) {print_it();
						st[p]++;}
			else{	
				if (as()) {	p++;
							st[p]=st[p-1]+1;
				}
				else {
					if (st[p]<n) {st[p]++;}
						else {	p--;
								st[p]=st[p]+1;
						}
				}
			}			
	}
}


int main(){
	citire();
	bt();
}