Pagini recente » Cod sursa (job #2324949) | Cod sursa (job #798744) | Cod sursa (job #2188543) | Cod sursa (job #2880470) | Cod sursa (job #2866229)
#include <fstream>
#include <iomanip>
#define nmax 30
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");
int comb[nmax][nmax];
int n, k;
double v[nmax], mat[nmax][nmax];
void total()
{
for(int i=0; i<=n; i++)
comb[i][0] = 1;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=k; j++)
{
comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
}
}
}
int main()
{
in>>n>>k;
for(int i=1; i<=n; i++)
{
in>>v[i];
}
for(int i=0; i<=n; i++)
mat[i][0] = 1;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=k; j++)
{
mat[i][j] = mat[i-1][j] + mat[i-1][j-1] * v[i];
}
}
total();
//out<<comb[n][k]<<"\n";
out<<setprecision(6)<<mat[n][k]/(double)comb[n][k];
return 0;
}