Cod sursa(job #1696191)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 28 aprilie 2016 15:58:54
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include<fstream>
#include<iomanip>
using namespace std;
int n, k, i, j;
long long c[30][30];
long double sol, v[30], d[30][30];
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int main(){
    fin>> n >> k;
    for(i = 1; i <= n; i++){
        fin>> v[i];
    }
    c[0][0] = 1;
    for(i = 1; i <= n; i++){
        c[i][0] = 1;
        for(j = 1; j <= i; j++){
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
        }
    }
    d[1][1] = v[1];
    d[1][0] = 1;
    for(i = 2; i <= n; i++){
        d[i][0] = 1;
        for(j = 1; j <= i; j++){
            d[i][j] = d[i - 1][j] + d[i - 1][j - 1] * v[i];
        }
    }
    sol = d[n][k] / c[n][k];
    fout<< setprecision(6) << fixed << sol <<"\n";
    return 0;
}