Pagini recente » Cod sursa (job #2569650) | Cod sursa (job #2054156) | Cod sursa (job #1184335) | Cod sursa (job #141119) | Cod sursa (job #1890448)
#include <stdio.h>
using namespace std;
short int n,m,sol[19];
void init(short int k) {
sol[k] = sol[k-1];
}
bool succesor(short int k){
if(sol[k]<n){
sol[k]++;
return true;
}
return false;
}
bool valid(short int k){
for(short int i=1;i<k;i++)
if(sol[k]==sol[i])
return false;
return true;
}
bool solutie(short int k){
return k==m;
}
void tipar(){
for(short int i=1;i<=m;i++)
printf("%d ",sol[i]);
printf("\n");
}
void bkt(){
int k=1;
init(k);
while(k){
if(succesor(k)){
if(valid(k)){
if(solutie(k))
tipar();
else init(++k);
}
}
else k--;
}
}
int main()
{
freopen("combinari.in","r",stdin);
freopen("combinari.out","w",stdout);
scanf("%hu%hu",&n,&m);
bkt();
return 0;
}