Cod sursa(job #1712361)
| Utilizator | Data | 2 iunie 2016 19:00:28 | |
|---|---|---|---|
| Problema | Dezastru | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
long double v[30];
long long nr[30],n,i,x,q,k,nt;
long double s,st;
int main()
{
f>>n>>k;
nr[0]=1;
for(i=1; i<=n; ++i)
{
f>>v[i-1];
nr[i]=nr[i-1]*i;
}
st=0;
nt=0;
for(x=0; x<(1<<n); ++x)
{
s=1;
q=0;
for(i=0; i<n; ++i)
if((x&(1<<i))!=0)
{
++q;
s*=v[i];
}
if(q==k)
{
nt+=nr[k];
st+=s*nr[k];
}
}
cout<<setprecision(7)<<fixed<<(long double)st/nt;
}
