Cod sursa(job #2810150)

Utilizator andrei_laurentiuRadu Andrei-Laurentiu andrei_laurentiu Data 28 noiembrie 2021 17:38:38
Problema Dezastru Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <bitset>

using namespace std;

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

bitset < 26 > viz(false);
int sol[27], total;
double ans = 0;
double pb[27];
double prob(int k)
{
    double ans = 1;
    for(int i = 1; i <= k; ++i)
        ans *= pb[sol[i]];
    return ans;
}

void bkt(int n, int k, int p)
{
    for(int i = sol[k-1] + 1; i <= n; ++i)
    {
        sol[k] = i;
        if(k == p)
        {
            ans += prob(p);
            total++;
        }
        else
            bkt(n, k + 1, p);
    }
}
int main()
{
    int n, p;
    fin>>n>>p;
    for(int i = 1; i <= n; ++i)
        fin>>pb[i];
    bkt(n, 1, p);
    fout<<ans / total;
    return 0;
}