Cod sursa(job #1550730)

Utilizator fromzerotoheroFROM ZERO fromzerotohero Data 14 decembrie 2015 17:00:09
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fi("combinari.in");
ofstream fo("combinari.out");

int n, m;
int st[19];

void write()
{
    for (int i = 1; i <= m; i++)
        fo << st[i] << " ";
    fo << "\n";

}

bool check(int k)
{
    for (int i = 1; i < k; i++)
        if (st[i] == st[k])
            return false;
    return true;
    
}

void comb(int k)
{
    for (int i = 1; i <= n; i++)
    {
        st[k] = i;
        
        if (check(k) && st[k] > st[k-1])
        {
            if (k == m)
                write();
            else
                comb(k + 1);
            
        }
        
    }
    
}

int main()
{
    fi >> n >> m;
    
    comb(1);
    
    return 0;
    
}