概率dp - UVA 11021 Tribles
2015-08-26 21:11
429 查看
Tribles
Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059
[b]Mean:[/b]有k个细菌,每个细菌只能存活一天,在死去之前可能会分裂出0,1,2....n-1个细菌,对应的概率为p0,p1,p2....pn-1。
问:所有细菌在第m天全部灭亡的概率是多少?(m天以前灭亡也算在内)
[b]analyse:[/b]
由于每一个细菌的生存是独立的,所以我们可以先算出一个细菌的概率为PP,最终答案应是:PP^k。
设dp[i]表示第i天全部灭亡的概率,那么:
dp[i] = p0*(dp[i-1]^0) + p1*(dp[i-1]^1) + p2*(dp[i-1]^2) + ...pn-1*(dp[i-1]^(n-1))
其中pi*(dp[j-1]^i)表示:该细菌分裂成了i个,这i个细菌在第j-1天灭亡的概率。
由于每个细菌独立,所以是乘法,也就是i次方。
对于dp[0],代表第0天就全部灭亡,也就是根本没有分裂,所以dp[0]=p0.
[b]Time complexity: O(N)[/b]
[b]Source code:[/b]
/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-08-26-20.36
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);
const int MAXN=1010;
double p[MAXN],dp[MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
scanf("%d",&t);
for(int Cas=1;Cas<=t;++Cas)
{
int n,k,m;
scanf("%d %d %d",&n,&k,&m);
for(int i=0;i<n;++i)
scanf("%lf",&p[i]);
dp[0]=p[0];
for(int i=1;i<m;++i)
{
dp[i]=0.;
for(int j=0;j<n;++j)
{
dp[i]+=p[j]*pow(dp[i-1],j);
}
}
printf("Case #%d: %.7f\n",Cas,pow(dp[m-1],k));
}
return 0;
}
/*
*/
相关文章推荐
- c++编译运行遇到的问题
- zoj3471 Most Powerful 状压dp
- spring AOP2
- 字符串及其操作函数
- match_parent和fill_parent的区别
- Java设计模式---工厂模式
- C/C++笔记(二) 2015/8/15
- 泛函编程(38)-泛函Stream IO:IO Process in action
- ui
- 使用 Linux 的 strace 命令跟踪/调试程序的常用选项
- 网络篇 - 03.NSURLConnection应用场景
- 使用 Linux 的 strace 命令跟踪/调试程序的常用选项
- jquery.autocomplete在火狐下的BUG解决
- MR案例:CombineFileInputFormat
- poj2752Seek the Name, Seek the Fame【kmp next数组应用】
- perl操作sybase
- 用类的形式用链表排序
- 网络篇 - 05.网络数据解析(XML)
- HDU2094 - 产生冠军 冠军: 总人数 - 失败过的人数 = 1
- tomcat memcached session 共享