Tribles

这篇博客探讨了一种名为Tribble的生物种群,在每代存活一天并有一定概率产仔的情况下,经过m代后所有个体消亡的概率。通过数学建模和概率计算,文章展示了如何根据个体的繁殖概率预测种群未来的命运。案例分析揭示了概率论在生物学问题中的应用,并提供了精确到小数点后七位的答案。
摘要由CSDN通过智能技术生成

GRAVITATION, n.
“The tendency of all bodies to approach one another with a strength
proportion to the quantity of matter they contain – the quantity of
matter they contain being ascertained by the strength of their tendency
to approach one another. This is a lovely and edifying illustration of
how science, having made A the proof of B, makes B the proof of A.”
Ambrose Bierce

You have a population of k Tribbles. This particular species of Tribbles live for exactly one day and then die. Just before death, a single Tribble has the probability Pi of giving birth to i more Tribbles. What is the probability that after m generations, every Tribble will be dead?
Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line
containing n (1 ≤ n ≤ 1000), k (0 ≤ k ≤ 1000) and m (0 ≤ m ≤ 1000). The next n lines will give the probabilities P0, P1, . . . , Pn−1.
Output
For each test case, output one line containing ‘Case #x:’ followed by the answer, correct up to an absolute or relative error of 10^−6.
Sample Input
4
3 1 1
0.33
0.34
0.33
3 1 2
0.33
0.34
0.33
3 1 2
0.5
0.0
0.5
4 2 2
0.5
0.0
0.0
0.5
Sample Output
Case #1: 0.3300000
Case #2: 0.4781370
Case #3: 0.6250000
Case #4: 0.3164062

#include <stdio.h>
double f[10001], p[10001];
double qw(double a, int b)
{
    double ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a;
        }
        a = a * a;
        b >>= 1;
    }
    return ans;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
#endif
    int i, j, n, k, m, N;
    scanf("%d", &N);
    for (int kcase = 1; kcase < N + 1; kcase++)
    {
        scanf("%d %d %d", &n, &k, &m);
        for (i = 0; i < n; i++)
        {
            scanf("%lf", &p[i]);
        }
        for (i = 1; i < m + 1; i++)
        {
            f[i] = p[0];
            if (i > 1)
            {
                for (j = 1; j < n; j++)
                {
                    f[i] += p[j] * qw(f[i - 1], j);
                }
            }
        }
        printf("Case #%d: %.7lf\n",kcase, qw(f[m], k));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值