Cod sursa(job #2810154)

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

using namespace std;

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

int sol[27], total;
double ans = 0;
double pb[27];


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