hdu 3203 Door Repairing(概率DP 反向推导)
来源:互联网 发布:博物君的淘宝店 编辑:程序博客网 时间:2024/05/22 18:36
hdu 3203 Door Repairing
对于一道门,n个人经过。每人有p的概率把门弄坏,修好门需要a元,若某人经过时门是坏的则罚b元。求期望的最小支出。
比较明显的概率dp题,关键是找出推导关系。本题中,如果所有人都通过了,那么门是好是坏也就不需要管了。有这个条件在,所以从后往前推导比较容易。
dp[n][0]表示第n个人经过时,门是坏的。dp[n][1]则表示门是好的。
dp[n][0] = min(dp[n+1][0]+b, a+p*dp[n+1][0]+(1.0-p)*dp[n+1][1]);
dp[n][1] = p*dp[n+1][0]+(1.0-p)*dp[n+1][1];
#include <stdio.h>#include <vector>#include <string>#include <algorithm>#include <queue>#include <cstring>#include <map>#include <set>#include <iostream>#include <cmath>using namespace std;// http://acm.hdu.edu.cn/showproblem.php?pid=3203#ifdef __GNUC__typedef long long LL;inline void opt64(LL a) { printf("%lld", a);}#elsetypedef __int64 LL;inline void opt64(LL a) { printf("%I64d", a);}#endifconst int MAXN = 100005;// 逆向推导int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif int n; double a, p, b; double f0, f1, p0, p1; while (scanf("%d%lf%lf%lf", &n, &p, &a, &b)) { if (n==0 && a==0 && p==0 && b==0) break; p /= 100.0; f0 = min(a, b); f1 = 0.0; for (int i = 1; i< n; ++i) { p0 = min(f0+b, a+p*f0+(1.0-p)*f1); p1 = p*f0+(1.0-p)*f1; f0 = p0; f1 = p1; } printf("%.4lf\n", f1); } return 0;}
0 0
- hdu 3203 Door Repairing(概率DP 反向推导)
- hdoj 3203 Door Repairing
- (概率DP)正向推概率,反向推期望
- hdu4089(公式推导)概率dp
- hdu 4652(概率dp)
- HDU Walk (概率DP)
- HDU 4987(概率dp)
- HDU 4405(概率dp)
- hdu 3583(概率dp)
- hdu 4576(概率dp)
- hdu - 4649 - Professor Tian(概率dp)
- hdu 4405 Aeroplane chess(概率dp)
- HDU 4576 Robot (概率dp)
- HDU 4576 Robot (概率DP)
- HDU 4405 Aeroplane chess (概率dp)
- hdu 4089 Activation(概率dp)
- hdu 4405 Aeroplane chess (概率dp)
- hdu 4089 Activation(概率dp)
- stl_pair.h
- Codeforces 86C Genetic engineering (AC自动机+dp)
- HDOJ 5057 Argestes and Sequence
- stl_list.h
- hdu 1814 Peaceful Commission 2-sat 按字典序输出
- hdu 3203 Door Repairing(概率DP 反向推导)
- stl_deque.h
- 动画类型 Android的animation由四种类型组成
- String的split()方法探索和大揭秘
- stl_stack.h
- 用 STC12C5A60S2 产生PWM波
- stl_queue.h
- Little Elephant and Array - CodeForces 220 B 树状数组
- on_exit()函数使用说明