Pagini recente » Cod sursa (job #1519147) | oji_andrei2 | Cod sursa (job #1060864) | Cod sursa (job #29940) | Cod sursa (job #304098)
Cod sursa(job #304098)
#include<stdio.h>
int st[20],top,n,k;
int evalid()
{
if(st[top]<=st[top-1])
return 0;
return 1;
}
void printsol()
{
for(int i=1;i<=top;i++)
printf("%d ",st[i]);
printf("\n");
}
int main()
{
int cand=0;
top=1;
st[top]=0;
freopen("combinari.in","r",stdin);
freopen("combinari.out","w",stdout);
scanf("%d %d",&n,&k);
while(top>0)
{
cand=0;
while(st[top]<n&&!cand)
{
st[top]++;
cand=evalid();
}
if(cand)
if(top==k)
printsol();
else
st[++top]=st[top-1];
else
top--;
}
return 0;
}