UVa 11021 Tribles (概率DP + 组合数学)
题意:有 k 只小鸟,每只都只能活一天,但是每只都可以生出一些新的小鸟,生出 i 个小鸟的概率是 Pi,问你 m 天所有的小鸟都死亡的概率是多少。
析:先考虑只有一只小鸟,dp[i] 表示 i 天全部死亡的概率,那么 dpi] = P0 + P1*dp[i-1] + P2*dp[i-1]^2 + ... + Pn*dp[i-1]^(n-1),式子 Pjdp[i-1]^j 表示该小鸟生了 j 后代,,它们在 i-1 天死亡的概率是 dp[i-1],因为有 j 只,每只都是 dp[i-1],所以就是 dp[i-1]^j。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 10;
const int maxm = 100 + 2;
const LL mod = 100000000;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} double p[maxn], dp[maxn]; int main(){
int T, k; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d %d %d", &n, &k, &m);
for(int i = 0; i < n; ++i) scanf("%lf", p + i);
dp[0] = 0; dp[1] = p[0];
for(int i = 2; i <= m; ++i){
dp[i] = p[0];
for(int j = 1; j < n; ++j) dp[i] += p[j] * pow(dp[i-1], j);
}
printf("Case #%d: %.6f\n", kase, pow(dp[m], k));
}
return 0;
}
UVa 11021 Tribles (概率DP + 组合数学)的更多相关文章
- 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 ...
- CF_229E_Gift_概率DP+组合数学
CF_229E_Gift_概率DP+组合数学 题目描述: 很久很久以前,一位老人和他的妻子住在蔚蓝的海边.有一天,这位老人前去捕鱼,他捉到了一条活着的金鱼.鱼说:“噢,老渔人!我祈求你放我回到海里,这 ...
- 概率dp - UVA 11021 Tribles
Tribles Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 Mean: 有k个细 ...
- UVA 11021 C - Tribles(概率DP)
记忆化就可以搞定,比赛里都没做出来,真的是态度有问题啊... #include <iostream> #include<cstdio> #include<cstring& ...
- UVA 11021 Tribles(递推+概率)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 [思路] 递推+概率. 设f[i]表示一只Tribble经 ...
- UVA - 11021 - Tribles 递推概率
GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the ...
- UVa 11021 - Tribles
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
随机推荐
- 关于vuex状态管理模式架构
一. 什么是vuex 集中存储管理所有组件的状态 并以相应的规则保证以一种可预测的方式发生变化. 例子: 实现加减 <p>{{count}} <button @click=" ...
- ajax添加header信息
$.ajax({url:"xxx",async:true,dataType:"json",contentType:"application/json& ...
- 【MINA学习笔记】—— 1.体系结构分析[z]
前言 Apache的MINA框架是一个早年非常流行的NIO框架,它出自于Netty之父Trustin Lee大神之手.虽然目前市场份额已经逐渐被Netty取代了,但是其作为NIO初学者入门学习框架是非 ...
- socketv 验证客户端链接的合法性
一 .socketv 验证客户端链接的合法性 send()与sendall() 验证客户端 加密验证 如果你想在分布式系统中实现一个简单的客户端链接认证功能,又不像SSL那么复杂,那么利用hmac+加 ...
- 模块二 hashlib模块、configparser模块、logging模块
算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常 ...
- jquery分页插件精选
1.最新的分页控件:Mricode.Pagination(推荐) https://github.com/mricle/Mricode.Pagination 2.Jquery Pagination Pl ...
- SQL新增数据取表主键最新值
string strsql = "insert into SB_Survey(title) values ('标题');select @@IDENTITY"; int s = in ...
- python 虚拟环境操作 virtualenv +virtualenvwrapper
Window 下创建python的虚拟环境 下载工具 pip install virtualenv 创建虚拟环境目录 # 注意此命令创建的虚拟环境目录是在当前目录下 virtualenv testen ...
- c#多线程下的进程同步SignalAndWait 使用简单说明
解释:向一个 WaitHandle 发出信号并等待另一个进入信号. 总体概述: .NET Framework中提供一些类用于手动进行线程间的访问同步.这些类主要分为3大类别(但正如下文中会看到的这些类 ...
- hdu 1026(BFS+输出路径) 我要和怪兽决斗
http://acm.hdu.edu.cn/showproblem.php?pid=1026 模拟一个人走迷宫,起点在(0,0)位置,遇到怪兽要和他决斗,决斗时间为那个格子的数字,就是走一个格子花费时 ...