Cod sursa(job #2058106)

Utilizator FrequeAlex Iordachescu Freque Data 5 noiembrie 2017 09:51:38
Problema Combinari Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

ifstream fin("combinari.in");
ofstream fout("combinari.out");

const int NMAX = 10;

int n, k;
int v[NMAX];

bool ok(int poz)
{
    if (v[poz - 1] > v[poz])
        return 0;
    for (int i = 1; i < poz; ++i)
        if (v[i] == v[poz])
            return 0;
    return 1;
}

void afis()
{
    for (int i = 1; i <= k; ++i)
        fout << v[i] << " ";
    fout << '\n';
}

void backtr(int poz)
{
    for (int i = 1; i <= n; ++i)
    {
        v[poz] = i;
        if (ok(poz))
        {
            if (poz == k)
                afis();
            else
                backtr(poz + 1);
        }
    }
}

int main()
{
    fin >> n >> k;
    backtr(1);

    return 0;
}