Cod sursa(job #2509700)

Utilizator dragos99Homner Dragos dragos99 Data 14 decembrie 2019 16:10:15
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<bits/stdc++.h>

using namespace std;
    ifstream f("dezastru.in");
    ofstream g("dezastru.out");

const int NMAX = 26;

int n, k;
vector<double> prob, fact(NMAX);
double dp[NMAX][NMAX];

int main()
{
    f>>n>>k;
    prob.resize(n);
    for(auto &x : prob){
        f>>x;
    }
    for(int i = 0 ; i <= n ; i++){
        dp[i][0] = 1;
        fact[i] = i ? fact[i - 1] * i : 1;
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= i ; j ++){
            dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] * prob[i - 1];
        }
    }

    double sol = dp[n][k] * fact[k] * fact[n - k] / fact[n];
    g<<sol;

    return 0;
}