Description
 

Problem A
Tribbles
Input: Standard Input

Output: Standard Output

GRAVITATIONn.
"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 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, NN 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 P0P1, ...,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 ;
}

最新文章

  1. iOS开发系列--C语言之指针
  2. JS 阶段小练习~ 无缝滚动
  3. C++ Primer中文版(第5版)(顶级畅销书重磅升级全面采用最新 C++ 11标准)
  4. JVM学习笔记(三)------内存管理和垃圾回收【转】
  5. 乱码!Eclipse 的控制台console必须用GBK编码。
  6. 百度 迷你版 UMeditor富文本编辑器 使用方法
  7. 转】Maven学习总结(九)——使用Nexus搭建Maven私服
  8. git 基本使用
  9. 值栈与ognl
  10. 由 argv引出的main参数 分类: C/C++ 2014-11-08 18:00 154人阅读 评论(0) 收藏
  11. 拦截asp.net mvc输出流做处理, 拦截HTML文本(asp.net MVC版)
  12. spring +springmvc+mybatis组合web.xml文件配置
  13. Scrapy框架
  14. Python 编写一个有道翻译的 workflow 教程
  15. Java执行jar总结
  16. windows共享文件夹至centos系统文件夹下
  17. Windows PowerShell 入門(8)-関数編3
  18. 没有IDE的日子
  19. 使用ffmpeg搭建HLS直播系统
  20. SVM的代码实现-python

热门文章

  1. [转] 再叙TIME_WAIT
  2. inverse 相关设置
  3. My way to Python - Day05 - 面向对象-思维导图
  4. 10.25 noip模拟试题
  5. 样式单位之px、em、rem
  6. 乐视手机查看运行内存方法、EUI(Eco User Interface)乐视系统查看手机运行内存方法
  7. Android中的Adapter 详解
  8. angularjs 将带标签的内容解析后返回
  9. IOS常用开源库
  10. HDU 4010.Query on The Trees 解题报告