Cod sursa(job #1185437)

Utilizator dragos03dragos popescu septimiu dragos03 Data 15 mai 2014 18:28:14
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include<fstream>
#include<iostream>
using namespace std;

ifstream f("combinari.in");
ofstream g("combinari.out");

int v[15],p,n,k;

void init()
{
    v[p]=0;
}
int succesor()
{
    v[p]++;
    if(v[p]<=n)
        return 1;
    return 0;
}
int valid()
{
    int i;
    for(i=1; i<p; i++)
        if(v[i]>=v[p])
            return 0;
    return 1;
}

int solutie()
{
    if(p==k)
        return 1;
    return 0;
}
void afisare()
{
    for(int i=1; i<=k; i++)
        g<<v[i]<<" ";
    g<<"\n";
}

void back()
{
    int as,ev;
    p=1;
    init();
    while(p>0)
    {
        as=1;
        ev=0;
        while(as&&!ev)
        {
            as=succesor();
            if(as)
                ev=valid();
        }
        if(as)
        {
            if(solutie())
                afisare();
            else
            {
                p++;
                init();
            }

        }
        else
        {
            p--;
        }
    }

}
int main()
{
    f>>n>>k;

    back();

    f.close();
    g.close();
    return 0;

}