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 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?
输入
are no more than 70 test cases.
input is terminated with 0. This test case is not to be processed.
输出
calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
演示样例输入
3
0.3 0.7
0.1 0.3 0.6
0
演示样例输出
3.41
提示
来源
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2luZGRyZWFtcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
+ E4 * P34 + 1
;
E2 = E2 *P22+ E4
* P24 + 1 ;
E1 =E1 *P11 + E2
*P12 +E3 * P13 + 1
;
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double dp[100][100] ;
double a , b , c , d , e ;
int i , j , n ;
int ff(int x,int y)
{
if( x <= n && y >=(n+1)-x )
return 1 ;
return 0 ;
}
void f()
{ return ;
}
int main()
{
while(scanf("%d", &n) && n)
{
scanf("%lf %lf", &a, &b);
scanf("%lf %lf %lf", &c, &d, &e);
memset(dp,0,sizeof(dp));
for(i = n ; i >= 1 ; i--)
{
for(j = (n+1)-i ; j <= n ; j++)
{
if(i == n && j == (n+1)-i) continue ;
else if( i == n )
dp[i][j] = 1.0*( dp[i][j-1] ) + 1.0 ;
else
{
if( j == (n+1)-i )
dp[i][j] = a*dp[i+1][j-1] + b*dp[i+1][j] + 1.0 ;
else
dp[i][j] = c*dp[i+1][j-1] + d*dp[i+1][j] + e*dp[i][j-1] + 1.0 ;
}
}
}
printf("%.2lf\n", dp[1][n]);
}
return 0;
}
sdut2623--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 ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- hdu 4336 Card Collector (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- 【概率dp】【数学期望】Gym - 101190F - Foreign Postcards
http://blog.csdn.net/DorMOUSENone/article/details/73699630
- [TS-A1489][2013中国国家集训队第二次作业]抽奖[概率dp]
概率dp第一题,开始根本没搞懂,后来看了09年汤可因论文才基本搞懂,关键就是递推的时候做差比较一下,考虑新加入的情况对期望值的贡献,然后推推公式(好像还是不太会推qaq...) #include &l ...
- 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 ...
随机推荐
- lua pbc
先要将proto文件编译成.pb文件,然后再动态绑定实现lua protobuffer,这就需要了解云风做的pbc的项目,地址为:https://github.com/cloudwu/pbc/blob ...
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- CH BR8(小学生放假了-clock()/CLOCKS_PER_SEC-斜率优化常错集锦)
小学生放假了 总时限 26s 内存限制 256MB 出题人 zsyzzsoft 提交情况 16/150 初始分值 1500 锁定情况 背景 我们能见到的最可怕的事情,莫过于小学生放假了! 描述 小学生 ...
- Java基础知识强化34:String类之String类的转换功能
1. String类的转换功能 String[] split(String regex)//将字符串变成字符串数组(字符串切割) byte[] getBytes()//将字符串变成字节数组 char[ ...
- C# 杨辉三角形算法
代码如下: static void Main(string[] args) { int[][] Array_int = new int[10][]; //向数组中记录杨辉三角形的值 for (int ...
- C#利用ODP.NET往oracle中高效插入百万数据
由于工作的原因,要使用winform来处理大量的数据,但是c#自带的System.data.OracleClient效率不是很高,在网上找了很久,找到了ODP.NET,是oracle为c#提供的.貌似 ...
- JS 无提示关闭当前窗口
function teseClose() { window.opener = null; window.open('','_self'); window.close(); }
- android sax解析xml 文件 动态加载标题
要解决一个问题 : 问题描述为 把标题动态的加载到 listView子布局中 我们首先通过 java程序写一个把标题写到xml文件的程序.这个程序会在以后讲解. 现在截图 已经写好的xm文件格式如下 ...
- (六)backbone - API学习 - Backbone路由
Backbone路由本质 Backbone路由分为两个大块,Router以及History用户在Router中定义相关规则,然后开启history.start进行路由监控,执行默认的回调所以,Rout ...
- c3p0写连接池 Demo
1.导包 2.配置文件:名称必须为:c3p0-config.xml,且必须放在src根目录下 <c3p0-config> <!-- 默认配置,有且仅可出现一次 ,如果没有指定则使用这 ...