Cod sursa(job #155240)

Utilizator a7893Nae Mihai a7893 Data 11 martie 2008 20:20:26
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include<stdio.h>
#define N 19
int n,k,st[N],k1,use[N];
void tipar()
{
	int i;
	for(i=1;i<k;i++)
		printf("%d ",st[i]);
	printf("%d\n",st[k]);
}
void back(int k1)
{
	int i;
	if(k1==k+1)
		tipar();
	else
		for(i=st[k1-1]+1;i<=n;i++)
			if(!use[i])
			{
				st[k1]=i;
				use[i]=1;
				back(k1+1);
				use[i]=0;
			}
}
int main()
{
	freopen("combinari.in","r",stdin);
	freopen("combinari.out","w",stdout);
	scanf("%d%d",&n,&k);
	back(1);
	return 0;
}