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

题意:给你 k个球,  一个球可以活一天,在它死的时候会有概率pi生出i个小球,(0<=i<n) 现在问你m天后 所有小球全部死亡的概率是多少

题解: 我们定义f[m] 为 一个小球 在活m天后死亡的概率 ,那么答案就是 f[m]^k

对于f[i] = P0 + P1 * (f[i-1]^1) + P2 * (f[i-1] ^ 2) + ............

递推得到答案

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std ;
  7. typedef long long ll;
  8.  
  9. const int N=;
  10.  
  11. int main() {
  12. int T, cas = , n, m, k;
  13. double p[N],f[N];
  14. scanf("%d",&T);
  15. while(T--) {
  16. scanf("%d%d%d",&n,&k,&m);
  17. for(int i = ; i < n ; i++) scanf("%lf",&p[i]);
  18. f[] = ;
  19. for(int i = ; i <= m ; i++) {
  20. f[i] = 0.0;
  21. for(int j = ; j < n ; j++) {
  22. f[i] += p[j] * pow(f[i-],j);
  23. }
  24. }
  25. printf("Case #%d: %.7f\n",cas++, pow(f[m],k));
  26. }
  27. return ;
  28. }

代码

UVA - 11021 - Tribles 递推概率的更多相关文章

  1. UVA 11021 - Tribles(概率递推)

    UVA 11021 - Tribles 题目链接 题意:k个毛球,每一个毛球死后会产生i个毛球的概率为pi.问m天后,全部毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率.那么 f(i)=p ...

  2. UVA 11021 Tribles(递推+概率)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经 ...

  3. UVA - 11021 Tribles 概率dp

    题目链接: http://vjudge.net/problem/UVA-11021 Tribles Time Limit: 3000MS 题意 有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新 ...

  4. 洛谷4316 绿豆蛙的归宿(DAG递推/概率dp)

    题目大意: 给定一个DAG,求起点到终点的路径长度期望 根据题意可以知道每一条边都有一定概率被走到 那么\(\displaystyle\begin{aligned} Ans = \sum_{e \in ...

  5. UVa 10520【递推 搜索】

    UVa 10520 哇!简直恶心的递推,生推了半天..感觉题不难,但是恶心,不推出来又难受..一不小心还A了[]~( ̄▽ ̄)~*,AC的猝不及防... 先递推求出f[i][1](1<=i< ...

  6. Uva 10446【递推,dp】

    UVa 10446 求(n,bcak)递归次数.自己推出来了一个式子: 其实就是这个式子,但是不知道该怎么写,怕递归写法超时.其实直接递推就好,边界条件易得C(0,back)=1.C(1,back)= ...

  7. UVa 10943 (数学 递推) How do you add?

    将K个不超过N的非负整数加起来,使它们的和为N,一共有多少种方法. 设d(i, j)表示j个不超过i的非负整数之和为i的方法数. d(i, j) = sum{ d(k, j-1) | 0 ≤ k ≤ ...

  8. LOJ#3093. 「BJOI2019」光线(递推+概率期望)

    题面 传送门 题解 把\(a_i\)和\(b_i\)都变成小数的形式,记\(f_i\)表示\(1\)单位的光打到第\(i\)个玻璃上,能从第\(n\)个玻璃下面出来的光有多少,记\(g_i\)表示能从 ...

  9. UVa 1645 Count (递推,数论)

    题意:给定一棵 n 个结点的有根树,使得每个深度中所有结点的子结点数相同.求多棵这样的树. 析:首先这棵树是有根的,那么肯定有一个根结点,然后剩下的再看能不能再分成深度相同的子树,也就是说是不是它的约 ...

随机推荐

  1. linux系统在线搭建禅道

    1.先安装wget:yum -y install wget 2.下载安装禅道:[root@zhaowen ~]# wget http://dl.cnezsoft.com/zentao/9.0.1/Ze ...

  2. docker(三):Harbor 1.8.0 仓库的安装和使用

    回顾: docker(一):docker是什么? docker(二):CentOS安装docker docker(部署常见应用):docker部署mysql 安装的先决条件 硬件环境 1.CPU    ...

  3. C# 开放式并发冲突报错处理

    1.调用DataSet.GetChanges()获取数据源中改变的数据 var data = ViewData.GetChanges() as ReleaseData; 2.为新增的数据 data 加 ...

  4. .NET WebForm 简介(9.19)

    WebForm是微软开发的一款产品,它将用户的请求和响应都封装为控件.让开发者认为自己是在操作一个windows界面.极大地提高了开发效率. WinForm是C/S(客户端) 主要是本机执行 WebF ...

  5. 找不到dll原因

    1.没有生成成功: A.代码有错误 B.引用dll有问题(dll生成失败|dll版本不对) C.源文件损坏 2.dll生成路径不对 3.对dll的引用丢失

  6. 第7章 性能和可靠性模式 Server Clustering(服务器群集)

    上下文 您正在设计要部署应用程序的基础结构层.运行要求包括无法满足的可用性或性能能力,因为基础结构中存在性能瓶颈或故障单点. 影响因素 设计基础结构时,请考虑下列影响因素: 用户希望在使用应用程序时这 ...

  7. Sql Server 连接池

    在看缓存的一篇文章中,看到连接池的三个字,来充充电. 原文连接 这篇讲了关键字 其实我们一直在使用SqlServer的连接池.在连接字符串中,Pooling为是否启用连接池,默认值为true,表示启用 ...

  8. (转)ORA-01502

    问题:ora-01502 索引或这类索引的分区处于不可用状态 引发:移动数据表分区,导致索引失效 解决:重建失效索引 1. select index_name ,status  from user_i ...

  9. iframe里面开启全屏allowfullscreen="true"

    <iframe id="J_iframe" width="100%" height="100%" src="client-a ...

  10. python与php生成二维码对比

    php生成二维码 include 引入的库单独下载 <?php header("Content-type:text/html;charset=utf-8"); error_r ...