zoj 3582 Back to the Past (概率dp)
2014-12-05 00:31
281 查看
题意给出一个余光宝盒(汗!)左右都有n个洞,每个洞亮的概率相同为p 求至少剩下m等的期望
四重循环枚举,暴力dp
设dp[i][j]表示左边i个亮,右边j个亮到达目标的期望
四重循环枚举,暴力dp
设dp[i][j]表示左边i个亮,右边j个亮到达目标的期望
#include<iostream> #include<math.h> #include<stdio.h> #include<algorithm> #include<string.h> #include<string> #include<vector> #include<queue> #include<map> #include<set> #include<stack> #define B(x) (1<<(x)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned ui; const int oo = 0x3f3f3f3f; //const ll OO = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; #define lson rt<<1 #define rson rt<<1|1 void cmax(int& a, int b){ if (b > a)a = b; } void cmin(int& a, int b){ if (b < a)a = b; } void cmax(ll& a, ll b){ if (b > a)a = b; } void cmin(ll& a, ll b){ if (b < a)a = b; } void cmax(double& a, double b){ if (a - b < eps) a = b; } void cmin(double& a, double b){ if (b - a < eps) a = b; } void add(int& a, int b, int mod){ a = (a + b) % mod; } void add(ll& a, ll b, ll mod){ a = (a + b) % mod; } const ll MOD = 1000000007; const int maxn = 55; double dp[maxn][maxn]; double C[maxn][maxn]; double p1[maxn], p2[maxn]; void GetC(){ for (int i = 0; i < maxn; i++){ C[i][0] = 1.0; for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; C[i][i] = 1.0; } } void Init(int n, double p){ p1[0] = 1.0; p2[0] = 1.0; for (int i = 1; i <= n; i++){ p1[i] = p1[i - 1] * p; p2[i] = p2[i - 1] * (1.0 - p); } } int main(){ int n, m; double p; GetC(); while (scanf("%d %d %lf", &n, &m, &p) != EOF){ if (n == 0 && m == 0) break; Init(n, p); memset(dp, 0, sizeof dp); for (int i = n; i >= 0; i--) for (int j = n; j >= 0; j--){ if (i >= m && j >= m) continue; for (int x = 0; x + i <= n; x++) for (int y = 0; y + j <= n; y++){ if (x == 0 && y == 0) continue; if (x <= n - i&&y <= n - j) dp[i][j] += dp[i + x][j + y] * C[n - i][x] * p1[x] * p2[n - x - i] * C[n - j][y] * p1[y] * p2[n - y - j]; } dp[i][j] = (dp[i][j] + 1.0) / (1.0 - p2[n - i] * p2[n - j]); } printf("%.6lf\n", dp[0][0]); } return 0; }
相关文章推荐
- ZOJ 3582 Back to the Past [概率DP]
- ZOJ 3582 Back to the Past(概率DP)
- ZOJ 3582 Back to the Past 概率DP
- ZOJ3582 Back to the Past
- ZOJ3582:Back to the Past(概率DP)
- ZOJ 3582 Back to the Past
- ZOJ3582:Back to the Past(概率DP)
- ZOJ10th 纪念赛B Back to the Past(期望DP)
- ZOJ 3949 Edge to the Root(树形DP)
- ZOJ3582---Back to the Past
- ZOJ 3223 Journey to the Center of the Earth DP+dijstra 二维最短路
- zoj 3605 Find the Marble (概率dp)
- DP--ZOJ - 1074 To the Max
- ZOJ 3949 Edge to the Root(树形DP)
- UVa 10828 Back to Kernighan-Ritchie 高斯消元+概率DP
- zoj1074 To the Max(简单的DP)
- zoj 2271 Chance to Encounter a Girl <概率DP>
- ZOJ 1074 To the Max【DP】【最大子段和】
- POJ 3259 Back to the past
- ZOJ 1074 To the Max(DP 最大子矩阵和)