Cod sursa(job #530269)
Utilizator | Data | 7 februarie 2011 13:28:34 | |
---|---|---|---|
Problema | Dezastru | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.56 kb |
#include<fstream.h>
#include<iomanip.h>
#define NMAX 32
double a[NMAX], p[NMAX], rez=0;
int n, i, k, x[NMAX], nr;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
inline void comb(int h)
{
int i;
if (h==k+1) { rez+=p[k];++nr;}
else
for (i=x[h-1]+1; i<=n-k+h; ++i)
{
x[h]=i;
p[h]=p[h-1]*a[i];
comb(h+1);
}
}
int main()
{
f>>n>>k;
for (i=1; i<=n; ++i) f>>a[i];
p[0]=1;
comb(1);
rez/=(double)nr;
g<<fixed<<setprecision(7)<<rez<<"\n";
f.close();
g.close();
return 0;
}