Cod sursa(job #2251682)

Utilizator LivcristiTerebes Liviu Livcristi Data 1 octombrie 2018 20:39:24
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <iomanip>
#define NUM 30
long double v[NUM];
long double comb[NUM][NUM];
long double mat[NUM][NUM];
int n, k;
using namespace std;
int main()
{
    ifstream f ("dezastru.in");
    ofstream g ("dezastru.out");

    for(int i = 0; i < NUM; i++)
        comb[i][0] = 1;
    for(int i = 1; i < NUM; i++)
        for(int j = 1; j <= i; j++)
            comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];

    f >> n >> k;
    for(int i = 1; i <= n; i++)
        f >> 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] + v[i] * mat[i - 1][j - 1];

    g << fixed << setprecision(10) << mat[n][k] / comb[n][k] << "\n";
    f.close();
    g.close();
}