13年山东省赛 The number of steps(概率dp水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

The number of steps

Time Limit: 1 Sec  Memory Limit: 128 M

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

概率dp大水题。。。

 1 #include <iostream>
 2 #include <sstream>
 3 #include <ios>
 4 #include <iomanip>
 5 #include <functional>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <string>
 9 #include <list>
10 #include <queue>
11 #include <deque>
12 #include <stack>
13 #include <set>
14 #include <map>
15 #include <cstdio>
16 #include <cstdlib>
17 #include <cmath>
18 #include <cstring>
19 #include <climits>
20 #include <cctype>
21 using namespace std;
22 #define XINF INT_MAX
23 #define INF 0x3FFFFFFF
24 #define MP(X,Y) make_pair(X,Y)
25 #define PB(X) push_back(X)
26 #define REP(X,N) for(int X=0;X<N;X++)
27 #define REP2(X,L,R) for(int X=L;X<=R;X++)
28 #define DEP(X,R,L) for(int X=R;X>=L;X--)
29 #define CLR(A,X) memset(A,X,sizeof(A))
30 #define IT iterator
31 typedef long long ll;
32 typedef pair<int,int> PII;
33 typedef vector<PII> VII;
34 typedef vector<int> VI;
35 double dp[110][110];
36 int main()
37 {
38     ios::sync_with_stdio(false);
39     int n;
40     while(cin>>n&&n){
41         double a,b,c,d,e;
42         cin>>a>>b>>c>>d>>e;
43         CLR(dp,0);
44         for(int i=n;i;i--){
45             for(int j = n+1-i;j<=n;j++){
46                 if(i==n&&j==(n+1-i))continue;
47                 else if(i==n)dp[i][j]=dp[i][j-1]+1.0;
48                 else if(j==(n+1-i))dp[i][j]=a*dp[i+1][j-1]+b*dp[i+1][j]+1.0;
49                 else dp[i][j]=c*dp[i+1][j-1]+d*dp[i+1][j]+e*dp[i][j-1]+1.0;
50             }
51         }
52         cout<<fixed<<setprecision(2)<<dp[1][n]<<endl;
53     }
54     return 0;
55 }
时间: 2024-08-07 21:20:51

13年山东省赛 The number of steps(概率dp水题)的相关文章

[2013山东ACM省赛] The number of steps (概率DP,数学期望)

The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 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 st

13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 2224: Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MB Description In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence.

[2013山东ACM]省赛 The number of steps (可能DP,数学期望)

The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; padding-right:0px; color:rgb(83,113,197); text-decoration:none; padding-top:0px"> Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Mary

13年山东省赛 Mountain Subsequences(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Mountain Subsequences Time Limit: 1 Sec  Memory Limit: 128 MB Description Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and flowers on the mountain,

【NOIP模拟赛】黑红树 期望概率dp

这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/2+1个黑(红),而且一定是差不多相间的(我就是因为没有看出来这里才会去想组合数,然后......),那么我们发现只要一奇一偶,就可以组成一对,因为偶数一定是平的因此,我们发现在掉下来的那对之前都是红黑或黑红,但是到了这里就是红红或黑黑了,我们只要求出(异色的概率)^(h/2-1)*(同色的概率)就

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

sdut2623--The number of steps(概率dp第一弹)

The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 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 st

hdu1212 Big Number &amp;第六届山东省赛Single Round Math (同余定理,大数取模)

题目链接:Big Number 题目大意:每次输入两个数,第一个是高精度,第二个数小于100000:求 a mod b 根据同余定理: (a+b)% c = (a%c+ b%c)%c (a*b)%c =  ( a%c* b%c)%c 所以 对于大数,例如 :123 可以这样分解 123 =  (1*10+2)*10 + 3: 123 % c =   (  (  (  1%c *  10%c)%c + 2%c) %c  * 10%c) + 3 %c  ) %c; 因此,我们用字符串处理这个数,通过

codeforce 804B Minimum number of steps

cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring,