Cod sursa(job #2553649)

Utilizator petrisorvmyVamanu Petru Gabriel petrisorvmy Data 22 februarie 2020 10:48:35
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>
#define FILE_NAME "dezastru"
#define fast ios_base :: sync_with_stdio(0); cin.tie(0);
#pragma GCC optimize("O3")
#define NMAX 1000010
using namespace std;

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef pair<ld,ld> pct;

const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;


void add(ll &a , ll b)
{
    a += b;
    a %= mod;
}

void sub(ll &a, ll b)
{
    a = (a - b + mod) % mod;
}

ld v[30], pd[30][30], fact[30];
ll n, k;
bitset <30> viz[30];

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

    for(int i = 2; i <= n; ++i)
        fact[i] = fact[i - 1] * i;

    pd[0][0] = 1;
    for(int i = 1; i <= n; ++i)
    {
        pd[i][0] = 1;
        for(int j = 1; j <= i; ++j)
            pd[i][j] = pd[i-1][j] + pd[i-1][j-1] * v[i];
    }
    g << setprecision(10);
    g << pd[n][k] * fact[k] * fact[n-k] / fact[n];
    f.close();
    g.close();
    return 0;
}