The number of steps(概率dp)
Description
Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms …). Now she stands at the top point(the first layer), and the KEY of this maze is in the lowest layer’s leftmost room. Known that each room can only access to its left room and lower left and lower right rooms .If a room doesn’t have its left room, the probability of going to the lower left room and lower right room are a and b (a + b = 1 ). If a room only has it’s left room, the probability of going to the room is 1. If a room has its lower left, lower right rooms and its left room, the probability of going to each room are c, d, e (c + d + e = 1). Now , Mary wants to know how many steps she needs to reach the KEY. Dear friend, can you tell Mary the expected number of steps required to reach the KEY?
Input
There are no more than 70 test cases.
In each case , first Input a positive integer n(0<n<45), which means the layer of the maze, then Input five real number a, b, c, d, e. (0<=a,b,c,d,e<=1, a+b=1, c+d+e=1).
The input is terminated with 0. This test case is not to be processed.
Output
Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
Sample Input
3 0.3 0.7 0.1 0.3 0.6 0
Sample Output
3.41
Hint
题解:
比如打靶打中8环的概率为0.3 ,打中7环的概率为0.7,那么打中环数的期望就是 8*0.3 + 7*0.7;
本题中我们用dp[i][j] 表示当前位置(i,j,表示房间的位置,最顶层的房间为(1,1),最低层最左边为(n,1))距离目的地还需要走的期望步数。那么目的地假设为dp[n][1] (根据建的坐标不一样,位置也不一样),那么dp[n][1]的值为0,因为已经到达目的地,不需要再走了。那么我们所求的就是dp[1][1] 开始的地方。所以解题的过程,就是一个逆推的过程。整个逆推过程完成,dp[1][1]内的值就是所求的期望步数。
代码:
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define is_lower(c) (c >= 'a' && c <= 'z') #define is_upper(c) (c >= 'A' && c <= 'Z') #define is_alpha(c) (is_lower(c) || is_upper(c)) #define is_digit(c) (c >= '0' && c <= '9') #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define PI acos(-1) #define IO \ ios::sync_with_stdio(); \ cin.tie(); \ cout.tie(); #define For(i, a, b) for (int i = a; i <= b; i++) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; const ll inf = 0x3f3f3f3f; ; const ll inf_ll = (ll)1e18; const ll maxn = 100005LL; const ll mod = 1000000007LL; + ; double ans[N][N]; int main() { int n; while (cin >> n, n) { memset(ans, , sizeof(ans)); double a, b, c, d, e; cin >> a >> b >> c >> d >> e; For(i, , n) { ans[n][i] = ans[n][i - ] + ; } ; i >= ; i--) { ans[i][] = (ans[i + ][] + ) * a + (ans[i + ][] + ) * b; ; j <= i; j++) { ans[i][j] = (ans[i][j - ] + ) * e + (ans[i + ][j] + ) * c + (ans[i + ][j + ] + ) * d; } } printf(][]); } }
The number of steps(概率dp)的更多相关文章
- sdut2623--The number of steps(概率dp第一弹,求期望)
The number of steps Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Mary stands in a st ...
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- SDUT 2623 The number of steps (概率)
The number of steps Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Mary stands in a stra ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- UVALive-8138 Number Generator 概率dp+优化
题目链接:https://cn.vjudge.net/problem/UVALive-8138 题意 有一个随机数生成器,输出1-n的整数. 现在已经输出了k个数,问再取几个数才能使取出的所有数的个数 ...
- sdutoj 2623 The number of steps
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
随机推荐
- 【bzoj4724】[POI2017]Podzielno 二分
题目描述 B进制数,每个数字i(i=0,1,...,B-1)有a[i]个.你要用这些数字组成一个最大的B进制数X(不能有前导零,不需要用完所有数字),使得X是B-1的倍数.q次询问,每次询问X在B进制 ...
- ashx文件和aspx
ashx文件和aspx文件有什么不同? 我们先新建一个ashx文件看看: <%@ WebHandler Language="C#" Class="Handler&q ...
- [学习笔记]动态dp
其实就过了模板. 感觉就是带修改的dp [模板]动态dp 给定一棵n个点的树,点带点权. 有m次操作,每次操作给定x,y表示修改点x的权值为y. 你需要在每次操作之后求出这棵树的最大权独立集的权值大小 ...
- C语言指针大杂烩
By francis_hao Oct 31,2016 指针数组和数组指针 指针数组本身是个数组,数组的内容是指针.形如char *pa[].由于[]优先级高于*,pa先于[]结合表示pa是一个数组,p ...
- [poj 3281]最大流+建图很巧妙
题目链接:http://poj.org/problem?id=3281 看了kuangbin大佬的思路,还用着kuangbin板子orz http://www.cnblogs.com/kuangb ...
- Wpremig和Jhadgre的藏宝图(最大流+二分)
Wpremig和Jhadgre的藏宝图 题目链接:https://ac.nowcoder.com/acm/contest/333/M Description: Jhadgre在生日那天收到了一张神秘的 ...
- var result = eval('(' + data + ')');的学习
$.post("url", function(data) { //这里的function(data)这里的data是前端页面获取的后台的返回的数据: var result = ev ...
- Install the AWS Command Line Interface on Linux
Install the AWS Command Line Interface on Linux You can install the AWS Command Line Interface and i ...
- java基础知识(二)-----多态和构造函数
一:前言 最近由于面试了新浪公司,面试官问我的问题我都不知道,觉得自己好菜,所以最近决定再把java基础给搞一遍,真的觉得自己好菜.每天看一点,那个家伙说<java编程思想>最少要看三遍, ...
- P3076 [USACO13FEB]出租车Taxi
题目描述 Bessie is running a taxi service for the other cows on the farm. The cows have been gathering a ...