UVa11021 Tribles

概率 递推

每只麻球都是独立计算的。

可以递推,设f[i]表示一只麻球经过i天死光的概率,那么f[i]的k次方就是k只麻球经过i天死光的概率。

则f[i]=p[0]+p[1]*f[i-1]^1+p[2]*f[i-1]^2+...+p[n-1]*f[i-1]^(n-1)

↑直接死掉;生了一只,这一只在i-1天后死了;生了两只,这两只在i-1天后都死了...以此类推

 1 /*by SilverN*/
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 using namespace std;
 8 int n,k,m;
 9 double p[1010],f[1010];
10 int main(){
11     int T;
12     int i,j;
13     scanf("%d",&T);
14     int cas=0;
15     while(T--){
16         scanf("%d%d%d",&n,&k,&m);
17         for(i=0;i<n;i++)scanf("%lf",&p[i]);
18         memset(f,0,sizeof f);
19         f[0]=0;f[1]=p[0];
20         for(i=2;i<=m;i++){
21             for(j=0;j<n;j++){
22                 f[i]+=p[j]*pow(f[i-1],j);
23             }
24         }
25         printf("Case #%d: %.7f\n",++cas,pow(f[m],k));
26     }
27     return 0;
28 }
时间: 2024-10-21 21:44:21

UVa11021 Tribles的相关文章

UVA11021 Tribles[离散概率 DP]

UVA - 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 app

UVA-11021 - Tribles(概率期望)

链接uva-11021 题意:开始有k只麻球,每只都是活一天就死,每只死前都会有pi的概率生出i只麻球.求m天后麻球死光的概率. 思路:各个麻球的死亡都是独立的,求对于一个麻球而言,m天后死光的概率就是f[m] 由全概率公式f[i] = p0 + p1 * f(i - 1) + p2 * f(i - 1)^2 + p3 * f(i - 1)^3....pn-1 * f(i - 1)^n-1 因为是用f[i-1]表示一只麻球i-1天后全部死亡的概率,j只后代全部死亡就是f[i-1]^j,就是j次方

UVA 11021 - Tribles(概率递推)

UVA 11021 - Tribles 题目链接 题意:k个毛球,每个毛球死后会产生i个毛球的概率为pi,问m天后,所有毛球都死亡的概率 思路:f[i]为一个毛球第i天死亡的概率,那么 f(i)=p0+p1f(i?1)+p2f(i?1)2+...+pnf(i?1)n 然后k个毛球利用乘法定理,答案为f(m)k 代码: #include <stdio.h> #include <string.h> #include <math.h> const int N = 1005;

uva 11021 Tribles

https://vjudge.net/problem/UVA-11021 k只麻球,每只活一天就死亡,临死之前可能会生成0——n-1只麻球 给出 生成i只麻球的概率p, 问m天后所有麻球都死亡的概率 令dp[i]表示1只麻球产生的后代在前i天死亡的概率 定义 pj * dp[i-1]^j 表示1只麻球产生了j个后代,他们全在前i-1天死亡 dp[i]= Σ  p j*dp[i-1]^j ans=dp[m]^k #include<cmath> #include<cstdio> #de

【乱入】Uva11021麻球繁衍

就是根据概率公式入门算算. #include<bits/stdc++.h> const int N=1010; int n,m,k; double p[N],f[N]; int main(){ int T;scanf("%d",&T); for(int yql=1;yql<=T;yql++){ scanf("%d%d%d",&n,&k,&m); for(int i=1;i<=n;i++)scanf("

UVA 11021 Tribles(递推+概率)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经过i天之后死绝的概率,则有递推式: f[i]=p[0]+p[1]*(f[i-1]^1)+…p[n-1]*(f[i-1]^n-1) 最后答案为f[m]^k [代码] 1 #include<cstdio> 2 #include<cstring> 3 #define FOR(a,b,c) f

UVA 11021 - Tribles(概率)

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)的概率在

UVA - 11021 - Tribles 递推概率

GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the quantity of matter they contain – the quantity ofmatter they contain being ascertained by the strength of their tendencyto approach one another. This

UVa11021

11021 TribblesGRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the quantity of matter they contain – the quantity ofmatter they contain being ascertained by the strength of their tendencyto approach one