Link uva-11021
Test instructions: Start with K only hemp ball, each live one day die, every death will have pi probability of birth I only hemp ball. The probability of the death of the MA after M days.
Idea: The death of each hemp ball is independent, ask for a hemp ball, M days die the probability is f[m]
by full probability formula f[i] = P0 + p1 * F (i-1) + P2 * F (i-1) ^2 + p3 * F (i-1) ^3....pn-1 * F (i-1) ^n-1
Because it is to use f[i-1] to express a hemp ball i-1 the probability of death all, J offspring all death is F[i-1]^j, is the J-time side. Pj*f[i-1]^j said the fur ball, the birth of a J offspring, they all died in i-1 days.
So K-balls, M-days, the probability of death is f[m]^k.
Code:
#include <iostream> #include <cstdio> #include <cmath> #include <cstring>using namespace std; const int N = 1005;double P[n],f[n];int main () { int t; CIN >> T; int n,k,m; for (int ca = 1;ca <= t;ca++) { cin >> n >> k >> m; for (int i = 0;i < n;i++) scanf ("%lf", &p[i]); memset (F,0,sizeof (f)); F[1] = p[0]; Recursive for (int i = 2;i <= m;i++) {for (int j = 0;j < n;j++) F[i] + = P[j]*pow (f[i-1],j); } printf ("Case #%d:%.7lf\n", Ca,pow (F[m],k)); } return 0;}
Uva-11021-tribles (probability expectation)