Cod sursa(job #481499)

Utilizator SzabiVajda Szabolcs Szabi Data 31 august 2010 19:45:12
Problema Dezastru Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <stdio.h>

int v[26],n,k,kfact,nmkfact,nfact;
float a[26],ossz=0;

int fact(int k){
int i,temp=1;

for(i=2;i<=k;i++){
	temp=temp*i;}
return temp;
}


void osszead(){
float temp=1;
int i;

for(i=1;i<=k;i++){temp=temp*a[v[i]];}

ossz+=(temp*kfact*nmkfact);

}



void back(int p){
int i;

for(i=v[p-1]+1;i<=n;i++){
v[p]=i;

if(p==k){osszead();}else{back(p+1);}

}

}

int main(){
freopen("dezastru.in","r",stdin);
freopen("dezastru.out","w",stdout);

int i;

scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){scanf("%f",&a[i]);}

kfact=fact(k);
nfact=fact(n);
nmkfact=fact(n-k);


back(1);

ossz=ossz/nfact;

printf("%.6f",ossz);



return  0;
}