Cod sursa(job #2666020)
| Utilizator | Data | 31 octombrie 2020 17:50:56 | |
|---|---|---|---|
| Problema | Dezastru | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <fstream>
using namespace std;
ifstream f("dezastru.in");
ofstream g("dezastru.out");
int n, x[30], p, ct;
double sol[30], s;
void calcul()
{
double prob = 1;
for(int i = 1; i <= p; i++)
prob *= sol[x[i]];
s += prob, ct++;
}
void backt(int k)
{
for(int i = x[k - 1] + 1; i <= n; i++)
{
x[k] = i;
if(k >= p) calcul();
else backt(k + 1);
}
}
int main()
{
f >> n >> p;
for(int i = 1; i <= n; i++)
f >> sol[i];
backt(1);
g << s / ct;
return 0;
}