Cod sursa(job #322388)
Utilizator | Data | 8 iunie 2009 18:33:46 | |
---|---|---|---|
Problema | Combinari | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 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()
{
scanf("%hd %hd", &n, &k);
stiva = new short int[k];
stiva[0]=0;
back(1);
return 0;
}