Cod sursa(job #1712372)

Utilizator CrystyAngelDinu Cristian CrystyAngel Data 2 iunie 2016 19:19:11
Problema Dezastru Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <iomanip>
#include <fstream>
#include <map>

using namespace std;

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

map <long long,double> m;

long double v[30];

long long nr[30],n,i,q,k,nt,x1;
double s,st,x;

int main()
{
    f>>n>>k;
    nr[0]=1;
    for(i=1; i<=n; ++i)
    {
        f>>x;
        m[1<<(i-1)]=x;
        nr[i]=nr[i-1]*i;
    }
    st=0;
    nt=0;
    for(x=0; x<(1<<n); ++x)
    {
        s=1;
        q=0;
        x1=x;
        while(x1)
        {
            s*=m[x1^(x1&(x1-1))];
            x1=x1&(x1-1);
            ++q;
        }
        if(q==k)
        {
            nt+=nr[k];
            st+=s*nr[k];
        }
    }
    g<<setprecision(7)<<fixed<<(double)st/nt;
}