Cod sursa(job #2406259)

Utilizator bluestorm57Vasile T bluestorm57 Data 15 aprilie 2019 16:24:26
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <iomanip>

using namespace std;

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

const int Nmax = 31;
float a[31][31],b[31][31],v[31];
int n,k;

int main(){
    int i, j;
    f >> n >> k;
    for(i = 1 ; i <= n ; i++)
        f >> v[i];

    a[0][0] = b[0][0] = 1;

    for(i = 1 ; i <= n ; i++){
        a[i][0] = b[i][0] = 1;

        for(j = 1 ; j <= n ; j++){
            a[i][j] = a[i - 1][j] + v[i] * a[i - 1][j - 1];
            b[i][j] = b[i - 1][j - 1] + b[i - 1][j];
        }
    }

    g << fixed << setprecision(6) << a[n][k] / (float)b[n][k];


    return 0;
}