UVA - 11021 - Tribles 递推概率
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) + ............
递推得到答案
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll; const int N=; int main() {
int T, cas = , n, m, k;
double p[N],f[N];
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&k,&m);
for(int i = ; i < n ; i++) scanf("%lf",&p[i]);
f[] = ;
for(int i = ; i <= m ; i++) {
f[i] = 0.0;
for(int j = ; j < n ; j++) {
f[i] += p[j] * pow(f[i-],j);
}
}
printf("Case #%d: %.7f\n",cas++, pow(f[m],k));
}
return ;
}
代码
UVA - 11021 - Tribles 递推概率的更多相关文章
- UVA 11021 - Tribles(概率递推)
UVA 11021 - Tribles 题目链接 题意:k个毛球,每一个毛球死后会产生i个毛球的概率为pi.问m天后,全部毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率.那么 f(i)=p ...
- UVA 11021 Tribles(递推+概率)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经 ...
- UVA - 11021 Tribles 概率dp
题目链接: http://vjudge.net/problem/UVA-11021 Tribles Time Limit: 3000MS 题意 有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新 ...
- 洛谷4316 绿豆蛙的归宿(DAG递推/概率dp)
题目大意: 给定一个DAG,求起点到终点的路径长度期望 根据题意可以知道每一条边都有一定概率被走到 那么\(\displaystyle\begin{aligned} Ans = \sum_{e \in ...
- UVa 10520【递推 搜索】
UVa 10520 哇!简直恶心的递推,生推了半天..感觉题不难,但是恶心,不推出来又难受..一不小心还A了[]~( ̄▽ ̄)~*,AC的猝不及防... 先递推求出f[i][1](1<=i< ...
- Uva 10446【递推,dp】
UVa 10446 求(n,bcak)递归次数.自己推出来了一个式子: 其实就是这个式子,但是不知道该怎么写,怕递归写法超时.其实直接递推就好,边界条件易得C(0,back)=1.C(1,back)= ...
- 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 ≤ ...
- LOJ#3093. 「BJOI2019」光线(递推+概率期望)
题面 传送门 题解 把\(a_i\)和\(b_i\)都变成小数的形式,记\(f_i\)表示\(1\)单位的光打到第\(i\)个玻璃上,能从第\(n\)个玻璃下面出来的光有多少,记\(g_i\)表示能从 ...
- UVa 1645 Count (递推,数论)
题意:给定一棵 n 个结点的有根树,使得每个深度中所有结点的子结点数相同.求多棵这样的树. 析:首先这棵树是有根的,那么肯定有一个根结点,然后剩下的再看能不能再分成深度相同的子树,也就是说是不是它的约 ...
随机推荐
- HDU 2520 我是菜鸟我怕谁
2019-05-27 17:52:01 加油!!! 看题时候就要仔细,最后容易忘记%10000 #include <bits/stdc++.h> using namespace std; ...
- docker(三):Harbor 1.8.0 仓库的安装和使用
回顾: docker(一):docker是什么? docker(二):CentOS安装docker docker(部署常见应用):docker部署mysql 安装的先决条件 硬件环境 1.CPU ...
- 通过Hibernate实现添加功能
package com.demo.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org. ...
- [hihicoder][Offer收割]编程练习赛47
删除树节点 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...
- [hihocoder][Offer收割]编程练习赛43
版本号排序 不知道什么傻逼原因,就是过不了 #pragma comment(linker, "/STACK:102400000,102400000") #include<st ...
- vue-cli 安装
1 node 下载 http://nodejs.cn/download/ 安装 2 npm install vue-cli -g 3 vue init <template-n ...
- springdatajpa使用informix数据库出现no such column 异常的问题
本博客属原创,转载请注明出处 问题描述: 环境: spring data jpa版本4.0.3 informix驱动版本3.50.JC9 程序结构 jpa配置文件对应的jdbc配置 dao层继承jpa ...
- zmodem使用方法
无论有xshell还是secureCRT连接linux的时. 默认都用一个zmodem可以帮助window和linux之间传输文件 很方便和实用的工具. 不过默认是无法使用的 需要安装lrzsz软件 ...
- Win10 BackgroundTask
1.这里面详细的说明了后台任务的搭建 调用等 提示: 1.BackgroundTaskRegistration 里面有这两个事件 OnCompleted/Progress 主要用来UpdateUI 这 ...
- RabbitMQ学习之messageconver插件实现(Gson)
RabbitMQ已经实现了Jackson的消息转换(Jackson2JsonMessageConverter),由于考虑到效率,如下使用Gson实现消息转换. 如下消息的转换类的接口MessageCo ...