Cod sursa(job #1359726)
| Utilizator | Data | 25 februarie 2015 01:23:35 | |
|---|---|---|---|
| Problema | Combinari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
#define nmax 100
using namespace std;
ifstream fin ("combinari.in");
ofstream fout ("combinari.out");
int sol[nmax];
int n, k;
bool seen[nmax];
void print(){
for(int i=1; i<=k; i++) fout << sol[i] << " ";
fout << "\n";
}
void combinari(int x){
if(x > k) print();
else
for(int i=sol[x-1]+1; i<=n; i++){
if(!seen[i]){
sol[x]= i;
seen[i]= true;
combinari(x+1);
seen[i]= false;
}
}
}
int main(){
fin >> n >> k;
combinari(1);
return 0;
}
