Pagini recente » Cod sursa (job #2659560) | Cod sursa (job #2698117) | Cod sursa (job #3273274) | Cod sursa (job #8419) | Cod sursa (job #188195)
Cod sursa(job #188195)
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define LL long long
#define ULL unsigned long long
#define PB push_back
using namespace std;
double A[26][26];
double B[26];
int main(void){
int i,j,N,k,M;
ifstream in("dezastru.in");
ofstream out("dezastru.out");
in >> N >> M;
for (i=1;i<=N;i++)
in >> B[i];
A[0][0] = 1;
for(i=1;i<=M;i++)
for (j=1;j<=N;j++){
for (k=j-1;k>=0;k--)
A[i][j] += A[i-1][k];
A[i][j] *= B[j];
//out << A[i][j]<< " " << i << " " << j << "\n";
}
double sol = 0;
for(i=1;i<=N;i++)
sol += A[M][i];
for(i=2;i<=(N-M);i++)
sol *= i;
for(i=M+1;i<=N;i++)
sol /= i;
out.precision(6);
out << sol;
in.close();
out.close();
return 0;
}