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

刚开始没理解题意,看了题解之后也不太理解,现在好点了。

其实可以看作每个麻球的后代是独立的,后代的后代同理也是独立的。

一只麻球有P[j]的概率生j只后代,每只后代在i-1天后死亡的的概率是f[i-1],j只麻球即有pow(f[i-1], j)的概率在i-1天后死亡,即可得代码如下

 #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std; #define INF 0xffffff7
#define maxn 310
typedef unsigned long long ull;
/*
每只毛球族都只产生自己的后代,所以可以独立计算,f[i]表示1只毛球族i天后死亡的概率,最后的结果就是f(m)^k
对于每只毛球族后代又可以独立计算,所以
f[i]=p[0]+p[1]*f[i-1]+p[2]*f[i-1]^2+...+p[n-1]*f[i-1]^n-1
就是说一只毛球族,i天后死亡的概率就是,它的后代i-1天都死亡的概率
*/
int main()
{
int T;
scanf("%d", &T);
for(int kase = ; kase <= T; kase++)
{
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
double p[maxn];
for(int i = ; i < n; i++)
{
scanf("%lf", &p[i]);
}
double ans;
double f[maxn]; f[] = ;
f[] = p[];/*1只麻球1天后死亡的概率为p[0],即生出0只麻球的概率*/
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", kase, pow(f[m], k));
}
return ;
}

UVA 11021 - Tribles(概率)的更多相关文章

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

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

  2. UVA - 11021 Tribles 概率dp

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

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

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

  4. 概率dp - UVA 11021 Tribles

    Tribles Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 Mean: 有k个细 ...

  5. UVA 11021 Tribles(递推+概率)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经 ...

  6. UVA - 11021 - Tribles 递推概率

    GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the ...

  7. UVa 11021 - Tribles

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. Uva 11021(概率)

    题意:有k只麻球,每只只能活一天,但临死之前可能产生新麻球,生出i个麻球的概率为pi,给定m,求m天后所有麻球都死亡的概率 输入格式 输入一行为测试数据的组数T,每组数据第一行为3个整数n,k,m;已 ...

  9. UVa 11021 (概率 递推) Tribles

    Tribble是麻球? 因为事件都是互相独立的,所以只考虑一只麻球. 设f(i)表示一只麻球i天后它以及后代全部死亡的概率,根据全概率公式: f(i) = P0 + P1 * f(i-1) + P2 ...

随机推荐

  1. iOS开发UI篇—实现一个私人通讯录小应用【转】

    转一篇学习segue不错的教程 一.该部分主要完成内容 1.界面搭建                        2.功能说明 (1).只有当账号和密码输入框都有值的时候,登录按钮才能交互 (2). ...

  2. 简单的activemq的封装和使用

    天空中飘着小雨,实在是适合写代码的时节. 1 package ch02.chat; import java.io.Serializable; import javax.jms.Connection; ...

  3. oracle表分析

    analyze table tablename compute statistics; analyze index indexname compute statistics; 对于使用CBO很有好处, ...

  4. codeforce 600A - Extract Numbers

    学习string #include <bits/stdc++.h> #define eps 1e-8 #define M_PI 3.141592653589793 ; using name ...

  5. cygwin远程操作linux

    远程登录 1.ssh <username>@<IP> eg:ssh root@10.20.30.255 2.输入密码就OK 远程拷贝 1.scp -r <username ...

  6. springmvc 传递对象数组参数 property path is neither an array nor a List nor a Map

    Spring MVC 3: Property referenced in indexed property path is neither an array nor a List nor a Map ...

  7. 恒天云技术分享系列3 – KVM性能调优

    恒天云技术分享:http://www.hengtianyun.com/download-show-id-11.html KVM是什么 KVM 是 kernel-based Virtual Machin ...

  8. java 内部类的使用

    http://www.cnblogs.com/wenruo/p/5387995.html 内部类 就是在类中嵌套的另一个类. 非静态内部类 创建内部类的方式就是把类定义在外部类里面. class Ou ...

  9. Oracle-PLSQL Developer使用笔记

    1.新建菜单 command window ---->命令行,执行sql语句 sql window ---->执行sql语句,可导出CSV,TSV,HTML,XML等类型文件 report ...

  10. iOS---RunLoop深度剖析

    RunLoop 前言 RunLoop是iOS/OS开发中比较基础的一个概念,在苹果开发中用在事件处理,延迟加载,屏幕刷新等功能的处理,其实抛开语言,RunLoop是一个的架构模式,也就是RunLoop ...