Cod sursa(job #1451036)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 15 iunie 2015 20:37:52
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
/*
    If you can't explain it simply, you don't understand it well enough.
*/

#include <cstdio>
#include <algorithm>

using namespace std;

const int Nmax = 30;

int n , k , i , j;
int comb[Nmax][Nmax];

double D[Nmax][Nmax] , p[Nmax];

int main()
{
    freopen("dezastru.in","r",stdin);
    freopen("dezastru.out","w",stdout);
    
    scanf("%d %d", &n, &k);
    
    for (i = 1; i <= n; ++i)
        scanf("%lf", &p[i]);
    
    for (i = 0; i <= n; ++i)
        D[i][0] = 1,
        comb[i][0] = 1;
    
    for (i = 1; i <= n; ++i)
        for (j = 1; j <= i; ++j)
            D[i][j] = D[i-1][j] + D[i-1][j-1] * p[i],
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
    
    printf("%.6lf", D[n][k] / comb[n][k]);
    
    return 0;
}