Pagini recente » Cod sursa (job #2916133) | Cod sursa (job #2478536) | Cod sursa (job #2848526) | Cod sursa (job #3030301) | Cod sursa (job #235311)
Cod sursa(job #235311)
#include <fstream>
using namespace std;
int n,k;
int p;
int st[19];
fstream fin ("combinari.in",ios::in);
fstream fout("combinari.out",ios::out);
void citire(void){
fin>>n>>k;
}
int solutie(){
if (st[p]<=n && p==k)
return 1;
return 0;
}
int as(){
if (p<k && st[p]<=n-(n-p-1))
return 1;
return 0;
}
void print_it(){
for (int i=1;i<=k;i++)
fout<<st[i]<<" ";
fout<<endl;
}
void bt(){
p=1;
st[p]=1;
while (st[1]<=(n-k)+1){
if (solutie()) {print_it();
st[p]++;}
else{
if (as()) { p++;
st[p]=st[p-1]+1;
}
else {
if (st[p]<n) {st[p]++;}
else { p--;
st[p]=st[p]+1;
}
}
}
}
}
int main(){
citire();
bt();
}