Pagini recente » Borderou de evaluare (job #1549322) | Cod sursa (job #3333557) | Cod sursa (job #971533) | Cod sursa (job #971544) | Cod sursa (job #971545)
Cod sursa(job #971545)
#include<stdio.h>
#include<iostream>
using namespace std;
double destroy[32];
int n, k;
double product = 0;
double number = 0;
bool invers = 0;
double total[32][32];
int main() {
freopen("dezastru.in", "r", stdin);
freopen("dezastru.out", "w", stdout);
cin>>n>>k;
for( int i = 1; i <= n; ++i) {
cin>>destroy[i];
product *= destroy[i];
}
total[0][0] = 1;
for( int j = 0; j < k; ++j) {
for( int i = 0; i < n ; ++i)
if( total[j][i] != 0 ){
for( int l = i + 1; l <= n; ++l)
total[j+1][l] += total[j][i] * destroy[l];
}
}
for( int j = 0; j <= n; ++j)
product += total[k][j];
long long number = 1;
if( k < n/2)
k = n - k;
for( int i = k + 1; i <= n; ++i)
number *= i;
for( int i = 1; i <= n - k; ++i)
number /= i;
cout<< product/number;
return 0;
}