Cod sursa(job #1811675)

Utilizator raulmuresanRaul Muresan raulmuresan Data 21 noiembrie 2016 14:54:45
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>
#include<vector>
#include<string>
#include<iomanip>
#define modulo 666013

using namespace std;

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


string sir;
int i, n, k, j,contor,st,dr,sol,x,y;
double a[100];
double d[100][100]; //d[i][j] = suma prob. de a alege j prob. dintre primele i
int comb[100][100];

int main()
{
    fin >> n >> k;
    for(i = 1; i <= n; i++)
    {
        fin >> a[i];
    }


    d[0][0] = 1;
    for(i = 1; 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] * a[i]);
        }

    }

    comb[0][0] = 1;
    comb[1][1] = 1;comb[1][2] = 1;
    for(i = 2; i <= 25; i++)
     {
         for(j = 1; j <= 25;j++)
         {
             comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
         }
     }


    double sol = d[n][k]/comb[n][k + 1];
     fout<< setprecision(6) << sol <<"\n";

}