UVA11021 Tribbles

题目大意:n个麻球,第一天有k个,麻球生命期为一天,临近死亡前会有i的几率生出Pi个麻球。问m天后麻球全部死亡概率

 

设f[i]表示i天后一个麻球全部死亡的概率

有f[1] = P0

f[i] = P0 + P1 * f[1] + P2 * f[2]^2 + ... + Pi * f[i]^i + ... +Pn * f[n] ^ n

 

即:一个麻球在第一天结束生i个麻球,i个麻球会从第二天开始执行第一天的麻球的行为,因此i天后全部死亡对第二天的麻球来说就是i-1天后全部死亡。由于麻球死亡相互独立,只需i次方即可

 

最终答案f[m]^k

 

蛇皮自己写的pow被卡精度

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #include <cmath> 
 9 #define min(a, b) ((a) < (b) ? (a) : (b))
10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
12 inline void swap(int &a, int &b)
13 {
14     long long tmp = a;a = b;b = tmp;
15 }
16 inline void read(int &x)
17 {
18     x = 0;char ch = getchar(), c = ch;
19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
21     if(c == '-') x = -x;
22 }
23 const int INF = 0x3f3f3f3f;
24 const int MAXN = 1000 + 10;
25 int t,n,k,m;
26 double p[MAXN], dp[MAXN];
27 /*double pow(double a, int b)
28 {
29     double r = 1, base = a;
30     for(;b;b >>= 1)
31     {
32         if(b & 1) r *= base;
33         base *= base;
34     }
35     return r;
36 }*/
37 int main()
38 {
39     read(t);
40     int ca = 0;
41     for(;t;-- t)
42     {
43         ++ ca;
44         memset(dp, 0, sizeof(dp));
45         read(n), read(k), read(m);
46         -- n;
47         for(register int i = 0;i <= n;++ i) scanf("%lf", &p[i]);
48         dp[1] = p[0];
49         for(register int i = 2;i <= m;++ i)
50             for(register int j = 0;j <= n;++ j)
51                 dp[i] += p[j] * pow(dp[i - 1], j);
52         printf("Case #%d: %.7lf\n", ca, pow(dp[m], k));
53     }
54     return 0;
55 } 
UVA11021

 

posted @ 2018-01-19 11:05  嘒彼小星  阅读(160)  评论(0编辑  收藏  举报