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
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大水题。。。
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
double dp[][];
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n&&n){
double a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
CLR(dp,);
for(int i=n;i;i--){
for(int j = n+-i;j<=n;j++){
if(i==n&&j==(n+-i))continue;
else if(i==n)dp[i][j]=dp[i][j-]+1.0;
else if(j==(n+-i))dp[i][j]=a*dp[i+][j-]+b*dp[i+][j]+1.0;
else dp[i][j]=c*dp[i+][j-]+d*dp[i+][j]+e*dp[i][j-]+1.0;
}
}
cout<<fixed<<setprecision()<<dp[][n]<<endl;
}
return ;
}
13年山东省赛 The number of steps(概率dp水题)的更多相关文章
- The number of steps(概率dp)
Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...
- 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 2224: Boring Counting Time Limit: 3 Sec ...
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- 13年山东省赛 Mountain Subsequences(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Mountain Subsequences Time Limit: 1 Sec ...
- 2013成都网络赛 C We Love MOE Girls(水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4727 The Number Off of FFF (水题)
The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- LightOJ 1065 - Number Sequence 矩阵快速幂水题
http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...
- 【NOIP模拟赛】黑红树 期望概率dp
这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/ ...
随机推荐
- hdu1272并查集入门
小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 犯罪团伙 codevs 3554
这是一道经典的水题,提供两种方法:①深搜 ②并查集 NO.1 深度优先搜索: #include<iostream>#include<cstdio>#include<al ...
- 图片自动转换效果 jquery
http://www.16sucai.com/uploadfile/show5/switchable01/switchable/ <div class="maxpSlid" ...
- 基于cygwin构建u-boot(五)结尾:shell 工具
结尾,基于cygwin对u-boot的处理,很大一部分都是再处理 路径等相关的问题,只有一个涉及到gcc的参数配置. 为了达到顺利编译的目的,使用shell下的部分工具进行处理. 1.sed sed简 ...
- [模拟炉石](一)让游戏过程显示到cocos2d中
在上篇中,如果运行了fireplace的tests/full_game.py,这个程序将一个游戏过程在终端上运行完成,可以看到整个过程,那么第一步要做的就是将这个过程显示到cocos2d创建的场景中去 ...
- Java学习笔记--Swing
1.创建框架 AWT中Frame类用来描述顶层窗口,在Swing中,这个类的名为JFrame,它从Frame类扩展. JFrame是少数几个在Swing不用绘制在画布上的组件之一,因此,它的修饰部件( ...
- 选址问题lingo求解
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang model : sets : H/h1..h2/:x , y , e ; L/l1..l6/: a ...
- 最大子数组分治方案C++实现
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下实现最大子数组的分治策略,算法来自<算法导论> #include<iostr ...
- 通过IIS发布站点和VS2012自带发布网站
vs2012通过IIS发布站点 http://jingyan.baidu.com/article/0964eca2d7beeb8285f536bd.html 用VS2012自带发布网站 http:// ...
- angular中设置$http的post请求的数据传递格式
ArgularJS的$http方法支持全局设置: $http.defaults.headers.post["Content-Type"] = "application/x ...