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 天全部 ...
随机推荐
- Jquery开发插件的方法
Jquery未开发插件提供了两个方法: (1)Jquery.extend(object) -为Jquery类本身添加新的方法;代码如下: $.extend({ add:function(a,b) ...
- 解决iOS7中UITableView在使用autolayout时layoutSubviews方法导致的crash
近期公司项目上线后,出现了大量的crash,发生在iOS7系统上,和UITableView相关: Auto Layout still required after executing -layoutS ...
- linux里source、sh、bash、./有什么区别
在linux里,source.sh.bash../都可以执行shell script文件,那它们有什么不同吗? ----------- 1.source source a.sh 在当前shell内去读 ...
- TortoiseSVN是windows平台下Subversion的免费开源客户端。
一般我们都是先讲讲服务器的配置,然后再讲客户端的使用,但是在TortoiseSVN上,却可以反过来.因为,如果你的要求不高,只是想在本机,或者是可信任的局域网络中使用SVN版本控制,可以不需要安装SV ...
- 关于Qt信号与槽机制的传递方向性研究(结论其实是错误的,但是可以看看分析过程)
最近由于项目的需求,一直在研究Qt.信号与槽机制是Qt的一大特色,该机制允许两者间传递参数,依次来实现对象间的通信.这个参数会分别存在于信号的参数列表和槽函数的参数列表中.需要注意的是,若将槽函数绑定 ...
- Delphi 预编译指令
<Delphi下深入Windows核心编程>(附录A Delphi编译指令说明)Delphi快速高小的编译器主要来自Object PASCAL的严谨,使用Delphi随时都在与编译器交流, ...
- DllMain加载其他DLL造成的死锁问题及其解决办法
使用VS 2008新建一个MFC ActiveX工程,因为在工程里要用到GDI+.我习惯把初始化GDI+库的代码放在应用程序类的InitInstance函数,对应的销毁代码放在ExitInstance ...
- /export/App/zz/phantomjs-1.9.7-linux-x86_64/bin
/export/App/zz/phantomjs-1.9.7-linux-x86_64/bin
- CCPC A(模拟)
Secrete Master Plan Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- android adb经常使用的命令
1.adb--- 订购屏幕截取 :adb shell screencap -p | sed 's/\r$//' > outputs.png 2.jni ---命令 :$NDK/ndk-b ...