CodeForces 148D Bag of mice
2013-09-05 21:20
253 查看
1、UVa 11021 Tribles
题意:有k只麻球,每只只能活一天且在死前可能生出一些新麻球。它生出i个新麻球的概率分别为Pi,求在m天后,所有麻球均死亡的概率为多少(不足m天全死亡也算).
1 <= n <= 1000, 0 <= k, m <= 1000。
解法:设开始有一只麻球,m天后全部死亡的概率为f(m)。由于每个麻球独立生活,所以有:
1、所求为f(m)^k;
2、由全概率公式,f(m) = P0 + P1*f(i-1) + P2*f(i-1)^2 + P3*f(i-1)^3+....+P[n-1]*f(i-1)^(n-1)。 其中,P[k]*f(i-1)^k表示,当前麻球生了j个后代,它们在i-1天后全部死亡。
tag:math, probality, 递推
View Code
10、POJ 2096 Collecting Bugs,概率DP,求期望的入门题。
11、ZOJ 3329 One Person Game,概率DP,巧妙解决带环的问题。
12、HDU 4405 Aeroplane chess,很简单的概率DP,加了一点限制条件。
13、HDU 4089 Activation,很好的概率DP题,而且是区域赛原题,2011 Beijing。
14、HDU 3853 LOOPS,概率DP,水题。
15、SGU 495 Kids and Prizes,概率DP,可以看下,与其他的题不太一样- -。
16、CodeForces 148D Bag of mice,概率DP,最普通的,加了点限制条件。
题意:有k只麻球,每只只能活一天且在死前可能生出一些新麻球。它生出i个新麻球的概率分别为Pi,求在m天后,所有麻球均死亡的概率为多少(不足m天全死亡也算).
1 <= n <= 1000, 0 <= k, m <= 1000。
解法:设开始有一只麻球,m天后全部死亡的概率为f(m)。由于每个麻球独立生活,所以有:
1、所求为f(m)^k;
2、由全概率公式,f(m) = P0 + P1*f(i-1) + P2*f(i-1)^2 + P3*f(i-1)^3+....+P[n-1]*f(i-1)^(n-1)。 其中,P[k]*f(i-1)^k表示,当前麻球生了j个后代,它们在i-1天后全部死亡。
tag:math, probality, 递推
/* * Author: Plumrain * Created Time: 2013-10-29 13:27 * File Name: math-POJ-3744.cpp */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define CLR(x) memset(x, 0.0, sizeof(x)) typedef double matrix[10][10]; int a[50], n; double p; matrix cnt, A; void mtx_init() { cnt[0][0] = p; cnt[1][0] = 1.0 - p; cnt[0][1] = 1.0; cnt[1][1] = 0.0; A[0][0] = p*p + 1.0 - p; A[1][1] = 1.0; A[0][1] = A[1][0] = p; } inline void mtx_equ(matrix& A, matrix ret) { for (int i = 0; i < 2; ++ i) for (int j = 0; j < 2; ++ j) A[i][j] = ret[i][j]; } void mtx_mul(matrix& A, matrix B) { matrix ret; for (int i = 0; i < 2; ++ i) for (int j = 0; j < 2; ++ j){ ret[i][j] = 0; for (int k = 0; k < 2; ++ k) ret[i][j] += A[i][k] * B[k][j]; } mtx_equ(A, ret); } void mtx_pow(matrix& A, int n) { matrix ret; CLR (ret); ret[0][0] = ret[1][1] = 1; while (n){ if (n & 1) mtx_mul(ret, A); n >>= 1; mtx_mul(A, A); } mtx_equ(A, ret); } double cal(int n) { if (!n || n == 1) return 1; mtx_init(); mtx_pow(cnt, n-2); mtx_mul(A, cnt); return A[0][1]; } double gao() { double ret = 1.0 - cal(a[0]); for (int i = 1; i < n; ++ i) ret *= (1.0 - cal(a[i] - a[i-1])); return ret; } int main() { while (scanf ("%d", &n) != EOF){ cin >> p; for (int i = 0; i < n; ++ i) scanf ("%d", &a[i]); sort (a, a+n); printf ("%.7f\n", gao()); } return 0; }
View Code
10、POJ 2096 Collecting Bugs,概率DP,求期望的入门题。
11、ZOJ 3329 One Person Game,概率DP,巧妙解决带环的问题。
12、HDU 4405 Aeroplane chess,很简单的概率DP,加了一点限制条件。
13、HDU 4089 Activation,很好的概率DP题,而且是区域赛原题,2011 Beijing。
14、HDU 3853 LOOPS,概率DP,水题。
15、SGU 495 Kids and Prizes,概率DP,可以看下,与其他的题不太一样- -。
16、CodeForces 148D Bag of mice,概率DP,最普通的,加了点限制条件。
相关文章推荐
- CodeForces 148D Bag of mice —— 概率DP
- codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice 概率dp!!
- CodeForces 148D Bag of mice
- Codeforces 148D Bag of mice (概率dp)
- codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice(概率DP )
- CodeForces 148D Bag of mice [概率DP]
- CodeForces 148D Bag of Mice 概率DP
- Codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice 详解 (概率DP)
- CodeForces 148D Bag of mice
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
- CodeForces - 148D Bag of mice
- codeforces148D Bag of mice
- CodeForces 148D Bag of mice 概率DP
- CodeForces-148D Bag of mice 概率dp
- Codeforces-148D Bag of mice (概率DP)
- CodeForces - 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice(概率DP)