博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva11021 - Tribles(概率)
阅读量:5033 次
发布时间:2019-06-12

本文共 1932 字,大约阅读时间需要 6 分钟。

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

题解:求概率,由全概率公式可以得到f[i]=p[0]+p[1]f[i-1]+p[2]f[i-1]^2+......+p[n-1]f[i-1]^[n-1];

题意就是给你一系列概率代表生i个麻球的概率,让求m天后都死亡的概率;This particular species of Tribbles live for exactly one day and

then die.说明包括中途死的;p[j]*f[i-1]^j代表这个麻球生了j个后代,他们在I-1天全死亡的概率;由于是独立的所以是j次方;

最后结果还要k次方;

代码:

#include
#include
#include
#include
#include
using namespace std;#define mem(x,y) memset(x,y,sizeof(x))const int MAXN=1010;double p[MAXN],f[MAXN];int main(){ int T,n,k,m,kase=0; scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&k,&m); for(int i=0;i

  

转载于:https://www.cnblogs.com/handsomecui/p/4992228.html

你可能感兴趣的文章
vim如何配置go语言环境
查看>>
机器学习好网站
查看>>
解题:国家集训队 Middle
查看>>
响应者链
查看>>
redhat 7 源码安装 mysql5.5.49
查看>>
技术项目,问题
查看>>
Learning to rank (software, datasets)
查看>>
git常见问题
查看>>
.NETFramework:template
查看>>
HM16.0之帧内模式——xCheckRDCostIntra()函数
查看>>
Jmeter性能测试 入门
查看>>
安卓动画有哪几种?他们的区别?
查看>>
ssh 连接原理及ssh-keygen
查看>>
vs2013编译qt程序后中文出现乱码
查看>>
【转】IOS数据库操作SQLite3使用详解
查看>>
Android官方技术文档翻译——ApplicationId 与 PackageName
查看>>
【转】ButterKnife基本使用--不错
查看>>
【转】VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”...
查看>>
函数中关于const关键字使用的注意事项
查看>>
js随机数的取整
查看>>