Cod sursa(job #505777)
| Utilizator | Data | 3 decembrie 2010 22:49:47 | |
|---|---|---|---|
| Problema | Combinari | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
int main () {
short n,k,i=1,j,a[20],lib[20];
freopen ("combinari.in","r",stdin);
freopen ("combinari.out","w",stdout);
scanf ("%hd%hd",&n,&k);
for (j=1; j<=n; j++) lib[j]=1;
a[1]=0;
while (i) {
if (i>k) {
for (j=1; j<=k; j++) printf ("%hd ",a[j]);
printf ("\n");
i--;
}
else {
j=a[i]+1;
while (!lib[j]&&(j<=n)) j++;
if (j>n) {
lib[a[i]]=1;
i--;
}
else {
lib[a[i]]=1;
a[i]=j;
lib[j]=0;
i++;
a[i]=0;
}
}
}
return 0;
}
