Cod sursa(job #621893)

Utilizator SCBbestofS. Bogdan SCBbestof Data 16 octombrie 2011 21:50:07
Problema Combinari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include<cstdio>
int N,C,X[19];
void afis()
{	int i;
	for(i=1;i<=C;i++)
		printf("%d",X[i]);
	printf("\n");
}
bool continuare(int k)
{
	if ( (X[k]>X[k-1]) && (X[k]<=N) )
		return 1;
	return 0;
}
void back(int k)
{
	if(k>0)
		if(k>C)
		{
			afis();
			back(k-1);
		}
		else
		{
			X[k]++;
			if(continuare(k))
				back(k+1);
			else
				if(X[k]>=N)
				{
					X[k]=0;
					back(k-1);
				}
				else
					back(k);
		}
}
int main()
{
	freopen("combinari.in","r",stdin);
	freopen("combinari.out","w",stdout);
	scanf("%d%d",&N,&C);
	back(1);
	return 0;
}