uva 11021 数学概率 麻球
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 11021 - Tribles 题目链接 题意:k个毛球,每一个毛球死后会产生i个毛球的概率为pi.问m天后,全部毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率.那么 f(i)=p ...
- uva 11021 Tribbles 麻球繁衍 概率
题目链接: https://uva.onlinejudge.org/external/110/11021.pdf dp[x]的意义是某个麻球从出生到它和其后代全部死亡不超过x天的概率. 对于dp[x] ...
- 概率DP,递推(麻球繁殖,UVA 11021)
能想到是概率DP,但是定义状态dp[i][j]第i天剩j个麻球.然后麻球数量可能会繁殖到非常多,状态太多数组开不下,然后就不会了. 感觉自己总是轻易就放弃了,还是应该再思考一下,一般遇到这种想到DP但 ...
- UVA 11021 麻球繁衍
题意: 有K只麻球,每只生存一天就会死亡,每只麻球在死之前有可能生下一些麻球,生i个麻球的概率是pi,问m天后所有的麻球都死亡的概率是多少? 思路: 涉及到全概率公式,因为麻球的各种活动都 ...
- UVA 11021 繁衍麻球
题意: 一只麻球只能活一天,然后每天会生一次: 给出n,k,m: n代表有一只麻球一次最多生n-1只: 接下来n行分别是生0到n-1只的概率p[i]: k代表一开始有k只麻球:问m天后麻球死光的概率 ...
- Uva 11201麻球繁衍(设概率方程的技巧)
Link 题意 kkk个球,每个球只存在一天就死去,但死前有pip_ipi的概率生iii个球(i∈[0,n−1]i\in[0,n-1]i∈[0,n−1]) 问在mmm天以前死光的概率是多少(k,n, ...
- 【UVA】【11021】麻球繁衍
数序期望 刘汝佳老师的白书上的例题--参见白书 1 //UVA 11021 2 #include<cmath> 3 #include<cstdio> 4 #define rep ...
- UVa 11021 (概率 递推) Tribles
Tribble是麻球? 因为事件都是互相独立的,所以只考虑一只麻球. 设f(i)表示一只麻球i天后它以及后代全部死亡的概率,根据全概率公式: f(i) = P0 + P1 * f(i-1) + P2 ...
- 麻球繁衍(Tribbles 概率dp)
摘自:<算法竞赛入门经典-训练指南>-刘汝佳 题意: 有K只麻球,每只生存一天就会死亡,每只麻球在死之前有可能生下一些麻球,生i个麻球的概率是pi,问m天后所有的麻球都死亡的概率是多少? ...
最新文章
- 个人网站建设要避开这些“通病”
- Lucene——Field.Store(存储域选项)及Field.Index(索引选项)
- OpenCV C++ 06 - Histogram Equalization of a Grayscale image with OpenCV
- 1079. 延迟的回文数 (20)
- python学习笔记之装饰器、递归、算法(第四天)
- 二分查找基础概念与经典题目(Leetcode题解-Python语言)二分索引型
- linux设置时间为24小时制,设置时区
- DLUTOJ 1033 Matrix
- c# chart 各个属性_c# Chart设置样式
- java中instant_Instant
- 实对称矩阵的一些性质(不包含证明)
- YOLO算法是干嘛的?
- android 获取iccid imsi
- oracle远程不能访问权限,oracle限制远程访问
- VS2019即将完成…一切即将准备就绪
- 【数据共享】深度学习异常行为数据集—疲劳驾驶数据集—行为分析数据集
- 8051f CH375 优盘---ch375.c
- 工具:你一定要知道的项目管理高手常用10张图表
- 聊天室的功能实现(主要部分)
- Valve现在说Steam将“像样”支持Ubuntu 19.10
热门文章
- 队列 如何 判断 已满
- C语言实现选择排序——堆排序(大根堆、小根堆)
- 洛谷P3799 妖梦拼木棒 题解
- String为什么要用equals而不用==?
- Spring Boot 启动成功
- 蓝桥杯 试题 算法训练 无聊的逗 C++ 详解 - 未完善
- 示波器探头上的×10
- python顺时针旋转_python——n*n矩阵顺时针旋转90度
- linux centos7 iso镜像下载,CentOS Linux 7.9 (2009) iso镜像下载
- 扎心了,5年多工作经验,期望工资15k,HR只给了13k