Cod sursa(job #2026280)

Utilizator shantih1Alex S Hill shantih1 Data 24 septembrie 2017 10:39:59
Problema Dezastru Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>

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

long long p, P;
double dz, s, v[30], best[30][30], sum;
int tot, n, k, i, j;

int main () {
    
    fin >> n >> k;
    for (i = 1; i <= n; i++)
        fin >> v[i];
    
    best[0][0] = 1;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
        {
            if (i == j)     best[i][j] = best[i-1][j-1] * v[i];
            else if (j == 1)     best[i][j] = best[i-1][j] + v[i];
            else best[i][j] = best[i-1][j] + v[i] * best[i-1][j-1];
        }
    
    p = 1;
    for (i = k+1; i <= n; i++)
        p *= i;
    P = 1;
    for (i = 1; i <= n-k; i++)
        P *= i;
    
    p /= P;
    fout << best[n][k] / p << "\n";
    return 0;
}