Cod sursa(job #1379849)

Utilizator RonaldoPop Sebastian Paul Ronaldo Data 6 martie 2015 19:51:21
Problema Combinari Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int a[20],b[20];

void combinari(int k, int x, int y){
    if(k-1 == y){
        for(int i = 1; i <= y; i++)
            fout << a[i]<<" ";
            fout << endl;
    }
    else{
        for(int i = 1; i <= x; i++)
            if(!b[i] and a[k-1] < i){
                a[k] = i;
                b[i] = 1;
                combinari(k+1,x,y);
                b[i] = 0;
            }
    }
}

int main(){
    int n,k;
    fin >>n>>k;
    combinari(1,n,k);
    return 0;
}