Cod sursa(job #322390)

Utilizator SliMMStefan Saftescu SliMM Data 8 iunie 2009 18:34:39
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
/*
 * combinari.cpp
 *
 *  Created on: Jun 8, 2009
 *      Author: stefan
 */

#include <cstdio>

short int *stiva, n, k;

inline void afisare()
{
	for(int i=1;i<=k;++i) printf("%d ", stiva[i]);
	printf("\n");
}

void back(short int pas)
{
	if(pas < k+1)
	{
		for(stiva[pas] = stiva[pas-1]+1; stiva[pas]<n+1; ++stiva[pas])
			if(n-stiva[pas] >= k-pas) back(pas+1);
	}
	else
	{
		afisare();
	}
}

int main()
{
	freopen("combinari.in", "r", stdin);
	freopen("combinari.out", "w", stdout);

	scanf("%hd %hd", &n, &k);
	stiva = new short int[k];

	stiva[0]=0;
	back(1);

	return 0;
}