Tribles(概率)
Problem A
Tribbles
Input: Standard Input
Output: Standard Output
|
GRAVITATION, n. |
Ambrose Bierce
You have a population of kTribbles. 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, everyTribble 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 |
Sample Output |
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 |
Case #1: 0.3300000 Case #2: 0.4781370 Case #3: 0.6250000 Case #4: 0.3164062 |
题意:有K只麻球,每只只活一天,临死前会产仔,产i只小麻球的 概率为pi,问m天后所有麻球全部死亡的概率;
思路:因为每只麻球都是相互独立的,所以只需求刚开始只有一只麻球,m天后其后代全部死亡的概率f[m],然后k只麻球最后全部死亡的概率就是 pow(f[m],k);
对于一只麻球,m天全死亡包含第一天、第二天、、、、、第m天死亡事件,因此一只麻球第i天死亡的概率f[i] = p0 + p1*f[i-1] + p2*f[i-2]^2+.......+ pn-1*f[i-1]^(n-1);
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int test;
scanf("%d",&test);
for(int item = ; item <= test; item++)
{
int n,k,m;
double p[],f[];
scanf("%d %d %d",&n,&k,&m);
for(int i = ; i < n; i++)
scanf("%lf",&p[i]); f[] = ;
f[] = p[];
for(int i = ; i <= m; i++)
{
f[i] = ;
for(int j = ; j < n; j++)
f[i] += p[j] * pow(f[i-],j);
}
printf("Case #%d: %.7lf\n",item,pow(f[m],k));
}
return ;
}
Tribles(概率)的更多相关文章
- UVA - 11021 Tribles 概率dp
题目链接: http://vjudge.net/problem/UVA-11021 Tribles Time Limit: 3000MS 题意 有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新 ...
- 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 ...
- UVa 11021 Tribles (概率DP + 组合数学)
题意:有 k 只小鸟,每只都只能活一天,但是每只都可以生出一些新的小鸟,生出 i 个小鸟的概率是 Pi,问你 m 天所有的小鸟都死亡的概率是多少. 析:先考虑只有一只小鸟,dp[i] 表示 i 天全部 ...
- UVA11021 Tribles 概率dp
题目传送门 题意:开始有$k$只兔子,每只都是活一天就死,每只死前都会有$pi$的概率生出$i$只兔子.求$m$天后兔子死光的概率. 思路: 设$f[i]$为一只兔子在第i天死完的概率,那么答案就是$ ...
- UVA 11021 C - Tribles(概率DP)
记忆化就可以搞定,比赛里都没做出来,真的是态度有问题啊... #include <iostream> #include<cstdio> #include<cstring& ...
- UVA11021 Tribles[离散概率 DP]
UVA - 11021 Tribles GRAVITATION, n. “The tendency of all bodies to approach one another with a stren ...
- uva11021 - Tribles(概率)
11021 - Tribles GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthpr ...
- 概率dp - UVA 11021 Tribles
Tribles Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 Mean: 有k个细 ...
随机推荐
- MySQL(10):实体、实体表和外键(foreign key)
1.实体 数据库管理系统中的各种用于数据管理方便而设定的各种数据管理对象,如:数据库表.视图.存储过程等都是数据库实体.广义上讲,这些对象中所存储的数据也是数据库实体.因为它们也是确切存 ...
- python下载IGS观测数据
最近在学习GPS数据软件处理,经常需要下载数据练习,反复去网站上很麻烦,于是就写了一个小小的爬虫,用的是韩国的服务器,使用了python中的ftplib库实现的 今天稍微改了一下代码,可以选择卫星系统 ...
- Html5新增的语义化标签(部分)
2014年10月29日,万维网联盟宣布,经过接近8年的艰苦努力,html5的标准规范终于制定完成.这是互联网的一次重大变革,这也许是一个时代的来临! 总结一些h5新增的语义化标签,记录下来方便自己学习 ...
- 实现Android K的伪沉浸式
在Android 5.0之后引入了MD风格,从而状态栏沉浸也成为了一种设计习惯.而停留在之Android L之前的Android系统则不能直接实现沉浸式,这里就介绍一下如何实现Android K系列的 ...
- Windows的计划任务
阅读目录 一:什么是Windows的计划任务? 二:如何设置计划任务 三:高级设置计划任务 一:什么是Windows的计划任务? 在日常的工作中,我们都有一些固定的或临时性的工作,而每次在爱机前一坐, ...
- oracle 10g 恢复dmp文件。
1. 在winxp下,安装10g,默认选择,一路ok.(安装前自检出现dhcp警告,可直接忽略) 2.命令行,在xp下,输入sqlplus,即可启动,登陆用 sqlplus / as sysdba 用 ...
- jQuery 停止动画
jQuery stop() 方法用于在动画或效果完成前对它们进行停止. 停止滑动 点击这里,向上/向下滑动面板 实例 jQuery stop() 滑动演示 jQuery stop() 方法. jQue ...
- python中如何使用help命令?
python下 help()使用方法 查看python所有的modules:help("modules") 单看python所有的modules中包含指定字符串的modules ...
- phpcms(3) V9 常用函数 及 代码整理(转)
转自http://www.cnblogs.com/Braveliu/p/5103918.html 常用函数 及 常用代码 总结如下 <;?php //转换字符串或者数组的编码 str_chars ...
- Fedora 21 安装Infinality
原文地址: Fedora 21 用infinality美化你的字体 http://blog.csdn.net/element207/article/details/41746683 安装infinal ...