Cod sursa(job #764451)

Utilizator mi5humihai draghici mi5hu Data 5 iulie 2012 11:53:09
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>
#include <fstream>
using namespace std;

int n, k;
int rez[25];

void citeste() {
     ifstream f("combinari.in");
     f >> n >> k;
     f.close();     
}

void afiseaza() {
     for (int i = 1; i <= k; i++) {
         printf("%d ",rez[i]);
     }
     printf("\n");
}

void rezolva(int poz, int next_val) {
     if (poz == k + 1) {
         afiseaza(); 
         //printf("|");
         //getchar();
         return;      
     }
     if (next_val == n + 1) {
         return;              
     }
     
     
     for (int j = next_val; j <= n; j++) {
         rez[poz] = j;
         //printf("%d %d\n", poz, j);
         //getchar();
         rezolva(poz + 1, j + 1); 
     }
}

int main() {
    citeste();
    freopen ("combinari.out", "w" , stdout);
    rezolva(1, 1);
}