Cod sursa(job #3288312)

Utilizator EricRaiaEricRaia EricRaia Data 21 martie 2025 14:14:12
Problema Dezastru Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;

ifstream cin ("dezastru.in");
ofstream cout ("dezastru.out");

int x[26],n,p,nrperm,i;
double v[26],s;

void back(int k, double prod)
{
    for(int i=x[k-1]+1;i<=n;++i){
        x[k]=i;
        if(k==p){
            s=s+prod*v[x[k]];
            nrperm++;
        }
        else
            back(k+1, prod*v[x[k]]);
    }
}

int main()
{
    cin>>n>>p;
    for(i=1;i<=n;++i)
        cin>>v[i];
    back(1, 1);
    cout<<(double)s/nrperm;

    return 0;
}