Pagini recente » Cod sursa (job #731756) | Cod sursa (job #1927475) | Cod sursa (job #1299348) | Cod sursa (job #1013583) | Cod sursa (job #2949805)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 18;
ifstream f("combinari.in");
ofstream g("combinari.out");
int n, k, st[nmax+5];
bool ok(int pos) {
for(int i=1; i<pos; i++) if(st[i] >= st[pos]) return false;
return true;
}
void show() {
for(int i=1; i<=k; i++) g << st[i] << " ";
g << "\n";
}
void bt(int pos) {
for(int i=1; i<=n; i++) {
st[pos] = i;
if(!ok(pos)) continue;
if(pos == k) show();
else bt(pos+1);
}
}
int main() {
f >> n >> k;
bt(1);
return 0;
}