Pagini recente » Borderou de evaluare (job #607453) | Borderou de evaluare (job #51382) | Borderou de evaluare (job #685883) | Arhiva de probleme | Cod sursa (job #2666020)
#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;
}