Cod sursa(job #1148073)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 20 martie 2014 13:39:36
Problema Dezastru Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
#include <iomanip>
using namespace std;

double a[1005][1005], p[1005];
int n, k;

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

int main()
{
    fin >> n >> k;

    for (int i = 1 ; i <= n ; i++)
        fin >> p[i];

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

    for (int i = 1 ; i <= n ; i++)
    {
        for (int j = 1 ; j <= i ; j++)
        {
            //cout << i << "| (" << a[i-1][j] << " * " << (i-j) << " + " << a[i-1][j-1] << " * " << p[i] << " * " << j << ") / " << i;
            a[i][j] = (a[i - 1][j] * (i - j) + a[i - 1][j - 1] * p[i] * j) / i;
            //cout << " >> " << a[i][j] << "\n";
        }
        //cout << "\n\n";
    }

    fout << setprecision(6) << a[n][k];
    return 0;
}