Cod sursa(job #645007)

Utilizator sunt_emoSunt emo sunt_emo Data 7 decembrie 2011 23:00:12
Problema Dezastru Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <stdio.h>

short n,k,i,u;
float p,b[30];
int c=1,d=1;

void comb (int x,int m,double p1) {
    if (x==k) {
        p+=p1;
        return;
    }
    int i;
    for (i=m; i<=u+x; i++) comb (x+1,i+1,p1*b[i-1]);
}

int main () {
    freopen ("dezastru.in","r",stdin);
    freopen ("dezastru.out","w",stdout);
    scanf ("%hd%hd",&n,&k);
    u=n-k+1;
    for (i=1; i<=k; i++) {
    	c*=i;
    	d*=i;
    }
    for (; i<=n; i++) d*=i;
    for (i=0; i<n; i++) scanf ("%f",b+i);
    comb (0,1,1);
    printf ("%.6f\n",c*p/d);
    return 0;
}