Cod sursa(job #1041557)

Utilizator DeclinGogonea Andrei Declin Data 25 noiembrie 2013 22:10:25
Problema Combinari Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <cstdio>
using namespace std;
short st[21],k1,k,n;
void init()
{
    st[k]=st[k-1]+1;
}
int succesor()
{
    if((st[k]<n)&&((n-st[k]-1)>=(k1-k)))
    {
        ++st[k];
        return 1;
    }
    return 0;
}
void tipar()
{
    short i,j;
    j=k1-1;
    for(i=1;i<=j;++i)
    printf("%hd ",st[i]);
    printf("%hd\n",st[k1]);
}
void back()
{
    k=1;
    init();
    while(k!=0)
    {
        if (k==k1)
        {
            tipar();
            while (succesor()==0)
             --k;
        }
        else
        {
            ++k;
            init();
        }

    }
}
int main()
{
    freopen("combinari.in","r",stdin);
    freopen("combinari.out","w",stdout);
    scanf("%hd%hd",&n,&k1);
    back();
    return 0;
}