Cod sursa(job #1473251)

Utilizator alexandru.ghergutAlexandru-Gabriel Ghergut alexandru.ghergut Data 18 august 2015 21:51:45
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

void nextCombination(int index, int value, int a[], int K, int N,
                                    ofstream &g)
{
    if (index > K - 1 || value > N)
        return;

    a[index] = value;
    if (index == K - 1)
    {
        for (int i = 0; i <= index; i++)
            g << a[i] << ' ';
        g << '\n';
    }

    nextCombination(index + 1, value + 1, a, K, N, g);
    nextCombination(index, value + 1, a, K, N, g);
}

int main()
{
    int N, K;
    ifstream f("combinari.in");
    f >> N >> K;
    f.close();
    int a[K];

    ofstream g("combinari.out");
    nextCombination(0, 1, a, K, N, g);
    g.close();
    return 0;
}