Cod sursa(job #801290)

Utilizator kiralalaChitoraga Dumitru kiralala Data 23 octombrie 2012 21:22:07
Problema Combinari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
//combinari
#include<fstream>
using namespace std;
ifstream f("combinari.in");
ofstream o("combinari.out");
int n,m,x[20],k;
void initialize()
{
    x[k]=0;
}
int getnumber()
{
    if(x[k]<n)
    {
        x[k]++;
        return 1;
    }
    else
    return 0;
}

int valid()
{
    int l=1;
    if(k>1)

        if(!(x[k]>x[k-1]))

                l=0;


    return l;
}

int solutie()
{
    if(k==m)
        return 1;
    else
    return 0;
}

void scrie()
{
    for(int i=1;i<=k;i++)
        o<<x[i]<<' ';
    o<<"/n";
}

void back()
{
    int a;
    k=1;
    initialize();
    while(k>0)
    {
    do{}while((a=getnumber())&&!valid());
    if(a)

        if(solutie()) scrie();
            else
            {
                k++;
                initialize();
            }

    else
        k--;
    }

}

int main()
{
	f>>n>>m;
	back();
	f.close();
	o.close();
	return 0;
}