Pagini recente » Cod sursa (job #2294576) | Cod sursa (job #1693650) | Cod sursa (job #2940941) | Cod sursa (job #756936) | Cod sursa (job #1694041)
#include <bits/stdc++.h>
#define NMax 26
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
float fol[NMax],a[NMax];
int st[NMax];
float ANS;
int n,k,w,total;
void afisare(int k){
float p = 1;
for(int i = 1; i <= k; ++i){
p *= a[st[i]];
}
ANS = ANS + ((float)p / (float)total);
// g << '\n';
}
void back(int k){
for(int i = 1; i <= n; ++i){
if(!fol[i]){
fol[i] = 1;
st[k] = i;
if(k == w)
afisare(k);
back(k + 1);
fol[i] = 0;
}
}
}
int main()
{
f >> n >> w;
for(int i = 1; i <= n; ++i){
f >> a[i];
}
total = 1;
for(int i = n - w + 1; i <= n; ++i){
total *= i;
}
back(1);
g << fixed << setprecision(8) << ANS << '\n';
return 0;
}