Cod sursa(job #187794)

Utilizator socheoSorodoc Ionut socheo Data 5 mai 2008 15:10:37
Problema Combinari Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include<stdio.h>
#include<math.h>
int n,k,i,j,nr,a[20];
void baza2(int x)
{ nr=0;
 int q=1;
  while(x>0)
   { a[q]=x%2;
     x=x/2;
     if(a[q]==1) nr++;
     q++;
   }}
int main()
{ freopen("combinari.in","r",stdin);
  freopen("combinari.out","w",stdout);
 scanf("%d",&n);
  scanf("%d",&k);
 for(i=1;i<=pow(2,n);i++)
 { baza2(i);
  if(nr==k)
  { for(j=1;j<=n;j++)
     if(a[j]==1) printf("%d ",j);
    printf("\n");   }
  }

return 0;
}