Pagini recente » Cod sursa (job #1276626) | Cod sursa (job #2170636) | Cod sursa (job #848901) | Cod sursa (job #1853517) | Cod sursa (job #2548066)
#include <fstream>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n, k, v[32], nr;
double prob[32], res;
void citire() {
fin >> n >> k;
for(int i = 1; i <= n; i++)
fin >> prob[i];
}
void backtracking(int p,double prb) {
for(int i = v[p-1]+1; i <= n; i++) {
v[p]= i;
double newp = (double)prb*prob[v[p]];
if(p == k) {
nr++;
res = (double)res+newp;
} else
backtracking(p+1, newp);
}
}
int main() {
citire();
backtracking(1, double(1.0));
res = (double)res/ nr;
fout << res;
}