Pagini recente » Cod sursa (job #3206085) | Cod sursa (job #2712746) | Cod sursa (job #2417058) | Cod sursa (job #2914064) | Cod sursa (job #932632)
Cod sursa(job #932632)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define nmax 20
using namespace std;
ifstream f("combinari.in");
ofstream g("combinari.out");
int st[nmax], n, k;
void tipar() { for(int i=1; i<=k; i++) g<<st[i]<<" "; g<<"\n"; }
bool valid(int h) {
for(int i=0; i<h; i++) if(st[i]>=st[h]) return false;
return true;
}
void back(int h) {
for(int i=1; i<=n; i++) {
st[h] = i;
if(valid(h)) {
if(h==k) tipar();
else back(h+1);
}
}
}
int main() {
f>>n>>k;
back(1);
return 0;
}