Pagini recente » Cod sursa (job #572788) | Cod sursa (job #714792) | Cod sursa (job #757206) | Cod sursa (job #562248) | Cod sursa (job #1052906)
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream in("dezastru.in");
ofstream out("dezastru.out");
int N, M, sol[30], use[30];
double s, p[30], c;
void afis(){
int i;
double x = 1;
for(i = 1; i <= M; i++){
x *= p[sol[i]];
}
x *= use[M];
s += (x/c);
}
void backt(int k){
if(k == M + 1){
afis();
}else{
for(int i = sol[k - 1] + 1; i <= N - M + k; i++){
sol[k] = i;
backt(k + 1);
}
}
}
int main()
{
in >> N >> M;
c = use[1] = 1;
for(int i = 2; i <= N; i++){
c *= i;
use[i] = use[i - 1] * i;
}
for(int i = 1; i <= N; i++){
in >> p[i];
}
backt(1);
out << fixed << setprecision(6);
out << s;
return 0;
}