Pagini recente » Cod sursa (job #2838910) | Cod sursa (job #2549202) | Cod sursa (job #2194360) | Cod sursa (job #955299) | Cod sursa (job #2727666)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream cin("dezastru.in");
ofstream cout("dezastru.out");
int n, k;
long double total = 0, a[25];
int nr = 0;
void select(int x, int y, long double p = 1){
if(y > (n - x))
exit(1);
p *= a[x];
if(y == 0){
total += p;
nr++;
return;
}
for(int z = x + 1;z<(n - y + 1);z++){
select(z, y - 1, p);
}
}
int main(){
cin>>n>>k;
for(int x = 0;x<n;x++)
cin>>a[x];
for(int x = 0;x<(n - k + 1);x++){
select(x, k - 1);
}
cout<<setprecision(100)<<total/nr<<'\n';
return 0;
}