Cod sursa(job #651524)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 20 decembrie 2011 18:49:45
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <cstdio>

#define NMax 27

using namespace std;

int N, K, C[NMax][NMax];
double P[NMax], DP[NMax][NMax];

int main()
{
    freopen ("dezastru.in", "r", stdin);
    freopen ("dezastru.out", "w", stdout);
    scanf ("%d %d", &N, &K);
    for (int i=1; i<=N; ++i)
    {
        scanf ("%lf", &P[i]);
    }
    DP[0][0]=C[0][0]=1;
    for (int i=1; i<=N; ++i)
    {
        DP[i][0]=C[i][0]=1;
        for (int j=1; j<=K and j<=i; ++j)
        {
            DP[i][j]=DP[i-1][j]+P[i]*DP[i-1][j-1];
            C[i][j]=C[i-1][j-1]+C[i-1][j];
        }
    }
    printf ("%.7lf\n", DP[N][K]/C[N][K]);
    return 0;
}