Cod sursa(job #361870)

Utilizator DragosPopaDragos Popa DragosPopa Data 6 noiembrie 2009 22:01:46
Problema Combinari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include<fstream>
using namespace std;

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


typedef struct{

    int st[100];
    int top;
    int h;
} stiva;

stiva stack;
int n;



int init(stiva *s)
{
    if((*s).top>1)
    (*s).st[(*s).top]=(*s).st[(*s).top-1];
    else
    (*s).st[(*s).top]=0;
return 1;
}

int succesor(stiva *s)
{
    if((*s).st[(*s).top]<n-(*s).h+(*s).top)
    {
        (*s).st[(*s).top]++;
        return 1;
    }
    else
    return 0;
}

int valid(stiva s)
{
    return 1;
}

int solutie(stiva s)
{
    return s.top==s.h;
}

int tipar(stiva s)
{

    for(int i=1;i<=s.h;i++)
    g<<s.st[i]<<" ";
    g<<endl;
return 1;
}

int bktr()
{
    int as;
    stack.top=1;
    init(&stack);
    while(stack.top>0)
    {
        do{}
        while((as=succesor(&stack)) && !valid(stack));
        if(as)
        if(solutie(stack))
        tipar(stack);
        else
        {
            stack.top++;
            init(&stack);
        }
        else
        stack.top--;
return 1;
    }
}

int main()
{
    
    f>>n;
    f>>stack.h;
    bktr();
return 1;
}