Pagini recente » Istoria paginii utilizator/iulian24k | Statistici Neacsu Teodor (teoutzzz) | Cod sursa (job #1330444) | Profil alexia_diaconu07 | Cod sursa (job #438051)
Cod sursa(job #438051)
#include <stdio.h>
int N, K;
int i;
long int fact;
double prob[30], S;
void back (int k, double x, int last)
{
if (k == K + 1)
{
S += x;
fact ++;
}
else
{
for (i=last + 1; i<= N - K + k; ++i)
back (k + 1, x * prob[i], i);
}
}
int main()
{
FILE *f = fopen ("dezastru.in", "r");
FILE *g = fopen ("dezastru.out", "w");
fscanf (g,"%d %d", &N, &K);
for (i=1; i<=N; ++i)
fscanf (g,"%lf", &prob[i]);
back(1, 1, 0);
fprintf(g, "%lf\n", S / fact);
fclose(g);
fclose(f);
return 0;
}