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个细 ...
随机推荐
-
docker通过iptables修改或新增镜像映射端口
443 8088 22 端口是初始映射端口 [root@SERVER ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAM ...
-
JSHelper时间格式化
Helper.prototype.FormatDate = function (format) { var _now = new Date(); var o = { "M+": _ ...
-
Android Studio Gradle Build Running 特别慢的问题探讨
本文的本本win7 64bit 6G android studio2.1 在运行程序的时候Gradle Build Running 特别慢,一个helloworld都快2min了 1.开启gradle ...
-
ASP.NET MVC中,怎么使用jquery/ajaxForm上传文件
ajaxForm插件最好选择:jquery forms plugin. 以下为示例: Ajax.BeginForm @using (Ajax.BeginForm("YourAction&qu ...
-
SQL Server 监控 使用sp_trace_create
监控前言 上一节我们提到了MSSQL的基于SQL Event的监控,但是有些时候我们需要更加详细.适用于调优排错的监控.SQL Server内部运行的可见性是的查询调整.优化和综合排查成为可能!这一节 ...
-
http://venkatbaggu.com/file-upload-in-asp-net-mvc-using-dropzone-js-and-html5/
http://venkatbaggu.com/file-upload-in-asp-net-mvc-using-dropzone-js-and-html5/ http://www.cnblogs.co ...
-
非常好用的正则表达式";\\s+"; - 匹配任意空白字符
说起来,博主使用过的正则场景虽然不多,但是就是在这当中,我发现"\\s+"真好用! 详解 "\\s+" 正则表达式中\s匹配任何空白字符,包括空格.制表符.换页 ...
-
linux之SQL语句简明教程---UPDATE DELETE FROM
我们有时候可能会需要修改表格中的资料.在这个时候,我们就需要用到 UPDATE 指令.这个指令的语法是: UPDATE "表格名" SET "栏位1" = [新 ...
-
Django 个性化管理员站点
from django.contrib import admin # Register your models here. from .models import Moment class Momen ...
-
web应用/路由控制/视图函数/单表多表操作
一. 1.wen应用:BS架构的应用程序,B是浏览器,S:server(实现了wsgi协议)+ application https://www.cnblogs.com/liuqingzheng/art ...