UV 11021, uva11021
Ultraviolet A 11021-Tribles
Question Link
The probability that each ball will be generated after death is pi. After m days, ask the probability that all the balls will die.
Train of Thought: f [I] is the probability of death on day I of a ball, so
F(I) =P0 +P1F(I− 1) +P2F(I− 1) 2 +... +PNF(I− 1)N
Then k fur balls use the multiplication theorem. The answer isF(M)K
Code:
# Include <stdio. h> # include <string. h> # include <math. h> const int n= 1005; int t, N, k, m; double p [n], f [N]; int main () {int cas = 0; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & k, & m ); for (int I = 0; I <n; I ++) scanf ("% lf", & p [I]); f [0] = 0; f [1] = p [0]; for (int I = 2; I <= m; I ++) {f [I] = 0; for (int j = 0; j <n; j ++) f [I] + = p [j] * pow (f [I-1], j );} printf ("Case # % d: %. 7lf \ n ", ++ cas, pow (f [m], k);} return 0 ;}