uva 11021 数学概率 麻球
来源:互联网 发布:c语言模块化程序设计 编辑:程序博客网 时间:2024/06/06 10:49
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只麻球,每活一天就会死亡,但第二天可能会生一些麻球,具体是 生i个麻球的概率为pi ,求m天后所有麻球都死亡的概率。
思路:考虑全概率公式,求k只麻球m天后全死亡 ,因为死亡是独立事件,应用乘法 ,ans= f[m] ^k ,f[m] 为一只麻球m天后均死亡的概率。对于第i天,
f[i]=p0+p1*f[i-1]^1 +p2*f[i-1]^2 +…p(n-1)*f[i-1]^(n-1) (就是让i-1天所有的出生的麻球全部死亡,那么第i天麻球就没了。。)
f[m] 的概率有 f【m-1】得出。对,就是让第i-1天出生的麻球全部死亡。生产麻球的数目之间相加即可。
#include <bits/stdc++.h>using namespace std;double f[1010];double p[1010];int main(){ int t; cin>>t; int cas=1; while(t--) { int n,m,k; cin>>n>>k>>m; for(int i=0;i<n;i++) scanf("%lf",&p[i]); f[0]=0.0; f[1]=p[0]; for(int i=2;i<=m;i++) { f[i]=0; for(int j=0;j<n;j++) { f[i]+=p[j]*pow(f[i-1],j); } } double res=pow(f[m],k); printf("Case #%d: %.7f\n",cas++,res); }}
- uva 11021 数学概率 麻球
- UVA 11021 - Tribles (数学概率)
- uva 11427 数学-概率
- UVA 11181(数学概率)
- uva 11021 Tribles(数学:概率+递推)
- uva 11021 - Tribles(概率)
- uva 11021 Tribles 【概率】
- UVA 11021 Tribbles【概率】
- Uva 11427 Expect the Expected 概率dp 求数学期望
- uva 11021-Tribbles-全概率
- UVa 11021 Tribles / 概率DP
- UVA 11021 Tribles (概率dp)
- uva 11021 Tribbles 概率计算
- UVa 11021 Tribles(概率DP)
- uva 11021 推概率公式
- UVA 11021(概率DP)
- UVA-11021 - Tribles(概率期望)
- UVA 11021 Tribbles 概率问题+递推
- URAL 2019. Pair: normal and paranormal(***栈模拟)
- 总结一些js常用方法和语法
- 继承(面向对象篇)
- tp5 cache缓存简单使用
- LeetCode:60. Permutation Sequence,全排列的第n个子列
- uva 11021 数学概率 麻球
- Dubbo入门学习--协议及注册中心
- 心理学
- HttpClient的简单使用
- c++并发初步学习(1)
- 剑指offer-36.两个链表的第一个公共结点
- Python(12):通过CMD向python传参数
- 学习笔记:The Log(我所读过的最好的一篇分布式技术文章)
- 提取文件夹中.lib文件名到文本中