Pagini recente » Cod sursa (job #2770714) | Cod sursa (job #1615487) | Cod sursa (job #1517650) | Cod sursa (job #659863) | Cod sursa (job #2090985)
#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000001;
int x[30], n, p, nr;
double a[30], prob;
void calcul()
{
double prod = 1.0;
for(int i = 1; i <= p; ++i)
prod *= a[x[i]];
prob += prod;
nr++;
}
bool valid(int k)
{
for(int i = 1; i < k; ++i)
if(abs(x[i] - x[k]) < eps)
return false;
return true;
}
void solve()
{
int k = 1;
while(k > 0) {
while(x[k] < n) {
x[k]++;
if(valid(k))
if(k == p)
calcul();
else {
k++;
x[k] = 0;
}
}
k--;
}
}
int main()
{
freopen("dezastru.in", "r", stdin);
freopen("dezastru.out", "w", stdout);
ios::sync_with_stdio(NULL);
cin.tie(0);cout.tie(0);
scanf("%d %d", &n, &p);
for(int i = 1; i <= n; ++i)
scanf("%lf", &a[i]);
solve();
printf("%lf", prob / (double)nr);
return 0;
}