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/ ...
随机推荐
- VC编程命名方法
1.
- 安装python3.4
1.http://www.python.org下载适合自己机型的镜像文件 2.一路“next”到底,安装python到C盘上 3.计算机-属性-高级系统设置-环境变量,将刚刚安装的python路径添加 ...
- Scala学习笔记--隐式转换
隐式转换的规则:1.无歧义规则:隐式转换唯有不存在其他可插入转换的前提下才能插入 若编译器有两种方法修正x+y 如convert1(x)+y,convert2(x)+y,会报错2.单一调用规则:只尝 ...
- gtest编译小结(ubuntu 12.10 , gtest 1.6.0)
1 下载源码,解压之当前用户的主目录(~/) 2 进入make目录,执行make命令 cd ~/gtest-/make make 3 在ubuntu里编译出错,提示找不到lthread库.修改Make ...
- 《Programming WPF》翻译 第6章 3.二进制资源
原文:<Programming WPF>翻译 第6章 3.二进制资源 尽管ResourceDictionary和系统级别的资源适合于作为数据存在于对象中,然而,并不是所有的资源都能很好的满 ...
- 编译不通过:提示XXXX不是类或命名空间名 的解决办法
手动写了一个类,需要引入预编译头stdafx.h.结果编译时提示XXXX不是类或命名空间名. 处理方法:将#include "stdafx.h"放在最前面.
- 基于Android的物理类游戏,源代码(JAVA)分享
游戏视频DEMO:http://v.youku.com/v_show/id_XNTM5MzM1Mzg0.html?from=s1.8-1-1.2 说明:一个自己做的Android上的物理类游戏,物理引 ...
- 【HDU3371】Connect the Cities(MST基础题)
注意输入的数据分别是做什么的就好.还有,以下代码用C++交可以过,而且是500+ms,但是用g++就会TLE,很奇怪. #include <iostream> #include <c ...
- linux 网络Socket实战
Preface:就算调通API,也不值得太过自豪!!!悉心细心学习,最好的深度学习就是看-学...*.h/*.class ProtoType; 1,linux C ftp C/S简单实现 ftpS端码 ...
- Handler消息机制实现更新主UI
如下实现的是简单的更新主UI的方法,用Handler消息机制 将textview的内容每隔一秒实现num++ /* * handler消息机制 * asynctask异步任务 * * httpcli ...