uva11021 Tribles

175 篇文章 0 订阅
137 篇文章 0 订阅

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
P i of giving birth to i more Tribbles. What is the probability that
after m generations, every Tribble will be dead? Input The rst 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 P 0 ; P 1
; : : : ; P n

dpi 表示一个毛球,在i天之内全死光的概率。因为各个毛球的生死繁殖是独立的,可以写出转移方程

dpi=j=0n1pjdpi1j

最后的答案是 dpmk

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double dp[1010],p[1010];
int n,m,k;
int main()
{
    int i,j,k,T,K;
    scanf("%d",&T);
    for (K=1;K<=T;K++)
    {
        scanf("%d%d%d",&n,&k,&m);
        for (i=0;i<n;i++)
          scanf("%lf",&p[i]);
        for (i=0;i<=m;i++) dp[i]=0;
        for (i=1;i<=m;i++)
          for (j=0;j<n;j++)
            dp[i]+=p[j]*pow(dp[i-1],j);
        printf("Case #%d: %.7f\n",K,pow(dp[m],k));
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值