Pagini recente » Cod sursa (job #1992703) | Cod sursa (job #998132) | Cod sursa (job #768733) | Cod sursa (job #2385689) | Cod sursa (job #2727671)
#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 = 1;
void select(int x, int y, long double p = 1){
///if(y > (n - x))
/// exit(1); <--- never happens
p *= a[x];
if(y == 0){
total += p;
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);
}
for(int x = 1, y = n, z = k;z > 0;z--){
nr *= y--;
nr /= x++;
}
cout<<setprecision(100)<<total/nr<<'\n';
return 0;
}