Cod sursa(job #3294417)

Utilizator Cristian_NegoitaCristian Negoita Cristian_Negoita Data 22 aprilie 2025 19:59:12
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n, k, a[26], cnt = 0, used[26];
double p[26], s = 0;

void update()
{
    cnt++;
    double crt = 1;
    for(int i = 1; i <= k; i++)
        crt *= p[a[i]];
    s += crt;
}

void bkt(int poz)
{
    for(int i = (poz == 1 ? 1 : a[poz - 1] + 1); i <= n; i++)
    {
        if(!used[i])
        {
            used[i] = true;
            a[poz] = i;
            if(poz == k)
                update();
            else
                bkt(poz + 1);
            used[i] = false;
        }
    }
}

int main()
{
    fin >> n >> k;
    for(int i = 1; i <= n; i++)
        fin >> p[i];
    bkt(1);
    fout << fixed << setprecision(6) << s / cnt;

    return 0;
}