uva11021 - Tribles(概率)
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<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
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<n;i++)scanf("%lf",p+i);
mem(f,0);
f[1]=p[0];f[0]=0;
for(int i=2;i<=m;i++){
for(int j=0;j<n;j++){
f[i]+=p[j]*pow(f[i-1],j);
}
}
printf("Case #%d: %.7lf\n",++kase,pow(f[m],k));
}
return 0;
}
uva11021 - Tribles(概率)的更多相关文章
- UVA11021 Tribles 概率dp
题目传送门 题意:开始有$k$只兔子,每只都是活一天就死,每只死前都会有$pi$的概率生出$i$只兔子.求$m$天后兔子死光的概率. 思路: 设$f[i]$为一只兔子在第i天死完的概率,那么答案就是$ ...
- UVA - 11021 Tribles 概率dp
题目链接: http://vjudge.net/problem/UVA-11021 Tribles Time Limit: 3000MS 题意 有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新 ...
- 洛谷 UVA11021 Tribles
UVA11021 Tribles 题意翻译 题目大意 一开始有kk种生物,这种生物只能活1天,死的时候有p_ipi的概率产生ii只这种生物(也只能活一天),询问m天内所有生物都死的概率(包括m天前死 ...
- UVA11021 Tribles[离散概率 DP]
UVA - 11021 Tribles GRAVITATION, n. “The tendency of all bodies to approach one another with a stren ...
- 2018.11.08 UVA11021 Tribles(概率dp)
传送门 概率dpdpdp简单题. 设f[i]f[i]f[i]表示第iii天的答案. 然后枚举ppp数组从fi−1f_{i-1}fi−1转移过来就行了. 显然有fi=∑j=0npj∗(fi−1)jf_ ...
- UVA 11021 - Tribles(概率递推)
UVA 11021 - Tribles 题目链接 题意:k个毛球,每一个毛球死后会产生i个毛球的概率为pi.问m天后,全部毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率.那么 f(i)=p ...
- UVA 11021 - Tribles(概率)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...
- Tribles(概率)
Description Problem ATribblesInput: Standard Input Output: Standard Output GRAVITATION, n."Th ...
- UVa 11021 Tribles (概率DP + 组合数学)
题意:有 k 只小鸟,每只都只能活一天,但是每只都可以生出一些新的小鸟,生出 i 个小鸟的概率是 Pi,问你 m 天所有的小鸟都死亡的概率是多少. 析:先考虑只有一只小鸟,dp[i] 表示 i 天全部 ...
随机推荐
- C++ signal的使用
1.头文件 #include <signal.h> 2.功能 设置某一信号的对应动作 3.函数原型 typdef void (*sighandler_t )(int); sighan ...
- C#中网站根路径、应用根路径、物理路径、绝对路径,虚拟路径的区别
C#中网站根路径,请站点的最外一层 /表示 应用根路径 ~/表示,有时候C#程序路径并不是网站路径 物理路径 server.mappath("~/") 是指应用程序放在服务器硬盘的 ...
- 在InteliJ IDEA中写Dart及配置IDEA - Dart Plugin
此文运用的是优雅的Markdown而书 Dart官方建议使用的编译器是DartEditor,我下载下来看下,和Eclipse的界面很相像.对于Eclipse,我是既爱又恨,爱它的稳定,恨它的功能没有I ...
- html5储存篇(二)
indexedDB 相对于html5 中提到 web SQL Database,w3c已经明确声明放弃对其的继续支持,开始支持新的客户端数据库 indexedDB ,indexedDB 是一种no ...
- ASP.NET MVC 中的 T4
每次使用“添加视图”或“添加控制器”功能时,您都在 ASP.NET MVC 项目中使用 T4 模板.这些模板位于 Common7\IDE\ItemTemplates\CSharp\Web\MVC 2\ ...
- codeforces 508D . Tanya and Password 欧拉通路
题目链接 给你n个长度为3的子串, 这些子串是由一个长度为n+2的串分割得来的, 求原串, 如果给出的不合法, 输出-1. 一个欧拉通路的题, 将子串的前两个字符和后两个字符看成一个点, 比如acb, ...
- ASP.net WebAPI 上传图片
[HttpPost] public Task<Hashtable> ImgUpload() { // 检查是否是 multipart/form-data if (!Request.Cont ...
- WEB和APP谁是互联网未来
据中国多家权威报告显示,作为多年专业化互联网公司炎帝网络科技综合评估预测,预计2016年全球互联网设备将达到100亿部.如果届时全球人口达到73亿,意味着平均每人将有1.4部设备.智能交通将增长50倍 ...
- Java面试题收集学习整理1
1.java序列化.反序列化及serialVersionUID作用 ."=="和equals方法究竟有什么区别? .静态变量和实例变量的区别? 在语法定义上的区别:.Integer ...
- 【浏览器那些基础】Android平台有那些CPU类型
在编译Android应用的时候,需要配置支持的CPU类型,而目前Android支持的CPU类型包含了ARM和X86,所以在编译前需要指定CPU类型(不同的cpu的特性不一样): X86系列的 expo ...