Pagini recente » Cod sursa (job #326449) | Cod sursa (job #1926597) | Cod sursa (job #1702626) | Cod sursa (job #3167694) | Cod sursa (job #482599)
Cod sursa(job #482599)
#include <stdio.h>
typedef int tipus1;
typedef float tipus2;
tipus1 n,k,v[30],nfact,nkfact,kfact;
tipus2 a[30],sum=0;
tipus1 fact(tipus1 p){
tipus1 i,temp=1;
for(i=2;i<=p;i++){temp*=i;}
return temp;
}
void osszead(){
tipus1 i;
tipus2 temp=1;
for(i=1;i<=k;i++){temp*=a[v[i]];}
temp*=kfact*nkfact*2;
sum+=temp;
}
void back(tipus1 p){
tipus1 i;
for(i=v[p-1]+1;i<=n-k+p;i++){
v[p]=i;
if(p==k){osszead();}else{back(p+1);}
}
}
int main(){
freopen("dezastru.in","r",stdin);
freopen("dezastru.out","w",stdout);
tipus1 i;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){scanf("%f",&a[i]);}
nfact=fact(n);
nkfact=fact(n-k);
kfact=fact(k);
back(1);
sum/=nfact;
sum/=2;
printf("%.6f",sum);
return 0;}