Cod sursa(job #304098)
Utilizator | Data | 10 aprilie 2009 22:11:46 | |
---|---|---|---|
Problema | Combinari | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#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;
}