Cod sursa(job #2866229)

Utilizator tibi25Ned Edu tibi25 Data 9 martie 2022 14:41:26
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <iomanip>
#define nmax 30

using namespace std;

ifstream in("dezastru.in");
ofstream out("dezastru.out");

int comb[nmax][nmax];

int n, k;

double v[nmax], mat[nmax][nmax];

void total()
{
    for(int i=0; i<=n; i++)
        comb[i][0] = 1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
        }
    }
}

int main()
{
    in>>n>>k;
    for(int i=1; i<=n; i++)
    {
        in>>v[i];
    }
    for(int i=0; i<=n; i++)
        mat[i][0] = 1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            mat[i][j] = mat[i-1][j] + mat[i-1][j-1] * v[i];
        }
    }
    total();
    //out<<comb[n][k]<<"\n";
    out<<setprecision(6)<<mat[n][k]/(double)comb[n][k];
    return 0;
}