Cod sursa(job #800962)

Utilizator kiralalaChitoraga Dumitru kiralala Data 22 octombrie 2012 22:49:35
Problema Combinari Scor 80
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,k,x[20],i;
void initialize()
{
    x[i]=0;
}
int getnumber()
{
    if(x[i]<n)
    {
        x[i]++;
        return 1;
    }
    return 0;
}

int valid()
{
    if(i>1)
    {
        if(!(x[i]>x[i-1]))
        {
                return 0;
        }
    }
    return 1;
}

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

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

void back()
{
    int a;
    i=1;
    while(i)
    {
    do{}while((a=getnumber())&&!valid());
    if(a)
    {
        if(solutie())
            scrie();
            else
            {
                i++;
                initialize();
            }
    }
    else
        i--;
    }

}

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