题目链接:

http://vjudge.net/problem/UVA-11021

Tribles

Time Limit: 3000MS

题意

有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新的麻球。生i个麻球的概率为pi,求m天后所有麻球死亡的概率。不足m天死光也算。

题解

每只麻球后代独立生存的,所以是独立概率。

设dp[i]表示一只麻球,i天后全部死亡的概率。有递推式:

dp[i]=p0+p1dp[i-1]+p2dp[i-1]2+...+pn-1*dp[i-1](n-1))

最后答案为dp[m]^k。

代码

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII; const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0); //start---------------------------------------------------------------------- const int maxn=1010; double pro[maxn];
double dp[maxn];
int n,k,m; int main() {
int tc,kase=0;
scf("%d",&tc);
while(tc--){
scf("%d%d%d",&n,&k,&m);
rep(i,0,n) scf("%lf",&pro[i]); dp[1]=pro[0];
for(int i=2;i<=m;i++){
dp[i]=0;
for(int j=0;j<n;j++){
dp[i]+=pro[j]*pow(dp[i-1],j);
}
} prf("Case #%d: %.7lf\n",++kase,pow(dp[m],k));
}
return 0;
} //end-----------------------------------------------------------------------

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

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

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

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

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

  3. UVA 11021 - Tribles(概率)

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

  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 C - Tribles(概率DP)

    记忆化就可以搞定,比赛里都没做出来,真的是态度有问题啊... #include <iostream> #include<cstdio> #include<cstring& ...

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

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

  7. UVA - 11021 - Tribles 递推概率

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

  8. UVa 11021 - Tribles

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

  9. Dumb Bones UVA - 10529(概率dp)

    题意: 你试图把一些多米诺骨牌排成直线,然后推倒它们.但是如果你在放骨牌的时候不小心把刚放的骨牌碰倒了,它就会把相临的一串骨牌全都碰倒, 而你的工作也被部分的破坏了. 比如你已经把骨牌摆成了DD__D ...

随机推荐

  1. mysql 跑存储过程没有权限的问题

    1.赋予权限 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; 2.刷新权限 FLUS ...

  2. 笔记2:MYSQL 表操作

    一.表约束 1.非空约束:not null 作用:定义表的某一列不能为空. >> alter table 表名 modify 列名 int not null; "添加非空约束&q ...

  3. 9 ORM-高阶补充(未完成)

    https://www.cnblogs.com/alice-bj/p/9195846.html#_labelTop https://www.cnblogs.com/yuanchenqi/article ...

  4. Kafka系列三 java API操作

    使用java API操作kafka 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...

  5. springmvc pager-taglib 分页,bootstrap样式

    注意: 嵌入到项目中时必须以带参形式访问: http://localhost:8081/DETECT-X/showConnLogsByPager.action?pageSize=5&pager ...

  6. anaconda 及python pip安装 类库等问题收集

    在win7下 通过anaconda安装jieba 报如下错误: 问题1:TypeError: parse() got an unexpected keyword argument 'transport ...

  7. mysql 中sql语句关键字的书写顺序与执行顺序

    书写顺序: select -> from -> where -> group by -> having -> order by 执行顺序: from -> wher ...

  8. centos7搭建ANT+jmeter+jenkins接口测试自动化环境

    一.环境准备 因为用到了jmeter和apache-tomcat,centos7必须要有java环境,所以配置jdk和apache-tomcat什么的,就不多说了,自行操作 帮你们偷懒: ant下载地 ...

  9. 模块化开发之butterknife 在 library中使用

    在Android开发中butterknife是一个很好的对资源初始化的工具,它可以使你的代码简洁通俗易懂,同时配合Android ButterKnife Zelezny插件可以让你写代码的速度提升至少 ...

  10. [Lua] 迭代器 闭合函数 与 泛型for

    首先看看一下闭合函数(closure),见如下代码: function newCounter() local i = 0 -- 非局部变量(non-local variable) return fun ...