Cod sursa(job #908511)

Utilizator deresurobertoFMI - Deresu Roberto deresuroberto Data 9 martie 2013 16:02:13
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include<cstdio>
int n,k,p,i,v[20];
bool ok;

void afisare()
{
	for(i=1;i<=p;i++)printf("%d ",v[i]);
	printf("\n");
}

void cont()
{
	ok=true;
	for(i=1;i<k;i++)
		if(v[i]>=v[k]){ok=false;break;}
}

bool succesor()
{
	bool ok1;
	ok1=false;
	if(v[k]<n-p+k){
		v[k]++;
		ok1=true;
	}
	if(ok1==true)return true;
	else return false;
}

int main()
{
	freopen("combinari.in","r",stdin);
	freopen("combinari.out","w",stdout);
	scanf("%d %d",&n,&p);
	k=1;v[k]=0;
	while(k>0){
		ok=false;
		while(not(ok) && succesor())cont();
		if (not(ok))k--;
		else if(k==p)afisare();
		else {
			k++;
			v[k]=0;
		}
	}
	return 0;
}