Pagini recente » Cod sursa (job #3203048) | Cod sursa (job #2006174) | Cod sursa (job #322568) | Cod sursa (job #121736) | Cod sursa (job #221247)
Cod sursa(job #221247)
#include<stdio.h>
int n,m,st[100];
long double p[100],sp;
void solutie(){
long double pr=1;
for(int i=1;i<=m;i++)
pr=pr*p[st[i]];
sp=sp+pr;
}
void bkt(int k,int x){
if(k==m+1) solutie();
else {
st[k]=x;
while(st[k]<n-m+k) {st[k]++;
bkt(k+1,st[k]);
}
}
}
int comb(int x,int y){
if(y==0||x==y) return 1;
else return comb(x-1,y-1)+comb(x-1,y);
}
int main(){
int i,c;
long double s=0;
freopen("dezastru.in","r",stdin);
freopen("dezastru.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
scanf("%Lf",&p[i]);
c=comb(n,m);
bkt(1,0);
s=sp/c;
printf("%Lf",s);
return 0;
}