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(概率)的更多相关文章

  1. UVA11021 Tribles 概率dp

    题目传送门 题意:开始有$k$只兔子,每只都是活一天就死,每只死前都会有$pi$的概率生出$i$只兔子.求$m$天后兔子死光的概率. 思路: 设$f[i]$为一只兔子在第i天死完的概率,那么答案就是$ ...

  2. UVA - 11021 Tribles 概率dp

    题目链接: http://vjudge.net/problem/UVA-11021 Tribles Time Limit: 3000MS 题意 有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新 ...

  3. 洛谷 UVA11021 Tribles

    UVA11021 Tribles 题意翻译 题目大意 一开始有kk种生物,这种生物只能活1天,死的时候有p_ipi​的概率产生ii只这种生物(也只能活一天),询问m天内所有生物都死的概率(包括m天前死 ...

  4. UVA11021 Tribles[离散概率 DP]

    UVA - 11021 Tribles GRAVITATION, n. “The tendency of all bodies to approach one another with a stren ...

  5. 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_ ...

  6. UVA 11021 - Tribles(概率递推)

    UVA 11021 - Tribles 题目链接 题意:k个毛球,每一个毛球死后会产生i个毛球的概率为pi.问m天后,全部毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率.那么 f(i)=p ...

  7. UVA 11021 - Tribles(概率)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...

  8. Tribles(概率)

    Description   Problem ATribblesInput: Standard Input Output: Standard Output GRAVITATION, n."Th ...

  9. UVa 11021 Tribles (概率DP + 组合数学)

    题意:有 k 只小鸟,每只都只能活一天,但是每只都可以生出一些新的小鸟,生出 i 个小鸟的概率是 Pi,问你 m 天所有的小鸟都死亡的概率是多少. 析:先考虑只有一只小鸟,dp[i] 表示 i 天全部 ...

随机推荐

  1. linux 虚拟文件系统----------Virtual File System VFSkky

    在了解虚拟文件系统之前,必须先知道什么是 Kernal  Space 与 User  Space. Kernal Space 与User Space 的差别,在于内存使用上安全机制的差异. kerna ...

  2. DEV GridControl 小结(持续添加)

    一.属性: 1.Views OptionsBehavior=>Editable:False  列表不可编辑 OptionsSelection=>EnableAppearanceFocuse ...

  3. 多线程笔记--原子操作Interlocked系列函数

    前面写了一个多线程报数的功能,为了描述方便和代码简洁起见,只输出最后的报数结果来观察程序运行结果.这非常类似一个网站的客户访问统计,每个用户登录用一个线程模拟,线程运行时将一个表示计数的变量递增.程序 ...

  4. MysqlHelp

    using System.Configuration;using MySql.Data: public class MySqlHelp { //链接字符串 private static string ...

  5. php基础知识(每天分享一些以前的笔记希望能帮助自学的朋友)

    php基础(第一天) php标签 1.  要知道php是一种嵌入html文档的脚本语言:php语法格式是:<?php 想要写的内容 ?>红色体就是php的标签,注意这些标签都要在英式输入法 ...

  6. hadoop配置及无法移动文件到hdfs故障解析

    首先博主用的64位ubuntu,hadoop官方只提供32位版本,这样的话启动本地库无法兼容,需要自己编译为64位版本,或下载别人编译好的64位版本. 下载好需要在etc/hadoop目录下改动以下几 ...

  7. Splunk

    http://www.huxiu.com/article/33724/1.html http://www.netis.com.cn/splunk/%E4%BB%80%E4%B9%88%E6%98%AF ...

  8. CI URL 辅助函数 url helper

    URL 辅助函数文件包含一些在处理 URL 中很有用的函数 加载辅助函数 本辅助函数通过如下代码加载: $this->load->helper('url'); 可用函数如下: site_u ...

  9. Dojo baseurl

    dojo.baseUrl baseUrl用来存储dojo.js存放 的跟目录,例如dojo.js的路径是“/web/scripts/dojo-1.3/dojo/dojo.js”则baseUrl为“/w ...

  10. Clojure绘制UML

    简单介绍 使用Clojure封装了Graphviz的使用.眼下主要实现了UML的绘制 使用 以命令模式的UML为例,演示cdraw的使用 安装Graphviz cdraw是对Graphviz的简单封装 ...