Pagini recente » Cod sursa (job #3157703) | Cod sursa (job #2481428) | Cod sursa (job #2603668) | Cod sursa (job #2854585) | Cod sursa (job #804467)
Cod sursa(job #804467)
#include<cstdio>
using namespace std;
FILE *f=fopen("combinari.in","r");
FILE *g=fopen("combinari.out","w");
int n,k,st[20];
bool ap[20];
int cresc(int v[], int lung)
{int i,e=1;
for (i=1;i<=lung && e;++i)
if (v[i]<v[i-1]) e=0;
return e;
}
int sol(int nr)
{
if (nr==k)
{if (cresc(st,nr)==0) return 0;
else return 1;
}
else return 0;
return 1;
}
void tipar()
{int i;
for (i=1;i<=k;++i)
fprintf(g,"%d ",st[i]);
fprintf(g,"\n");
}
void back(int nr)
{int i;
for (i=nr;i<=n;++i)
{st[nr]=i;
if (ap[st[nr]]==0)
{ap[st[nr]]=1;
if (sol(nr)) tipar();
else back(nr+1);
ap[st[nr]]=0;
}
}
}
int main()
{fscanf(f,"%d%d",&n,&k);
back(1);
return 0;
}