Cod sursa(job #627522)

Utilizator the_snyper06FMI - ALexandru Mihai the_snyper06 Data 30 octombrie 2011 03:47:34
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include<cstdio>

int n, k, top, cand;
int st[10];

bool EValid(int top)
{
	int i;
	
	for(i = 1; i < top; i++)
	{
		if(st[i - 1] >= st[i]) return false;
		if(st[i] == st[top]) return false;
	}
	if(st[i - 1] >= st[top]) return false;
	
	return true;
}

void Afisare(int n)
{
	int i;
	
	for(i = 1; i <= n; i++)
		printf("%d ", st[i]);
	printf("\n");
}

int main()
{
	freopen("combinari.in", "r", stdin);
	freopen("combinari.out", "w", stdout);
	
	scanf("%d %d", &n, &k);
	top = 1;
	st[top] = 0;
	
	while(top > 0)
	{
		cand = 0;
		while(!cand && st[top] < n)
		{
			st[top]++;
			cand = EValid(top);
		}
		
		if(!cand) top--;
		else if(top == k) Afisare(top);
		else st[++top] = 0;
	}
	
	return 0;
}