[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 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
提示
来源
解题思路:
比方打靶打中8环的概率为0.3 ,打中7环的概率为0.7,那么打中环数的期望就是 8*0.3 + 7*0.7
本题中对于左边没有屋子的仅仅能向左下和右下走,概率为a,b,对于左边。左下,右下都有屋子的,三种方向都能够走,概率为 e,c,d,对于没有左下,没有右下仅仅能向左走的概率为1.问从顶部到左下角期望走的步数。
就是求数学期望,但预先不知道离散的走的步数。所以须要用到期望的离散性质。
本题中我们用dp[i][j] 表示当前位置距离目的地还须要走的期望步数。那么目的地如果为dp[n][1] (依据建的坐标不一样,位置也不一样),那么dp[n][1]的值为0,由于不须要再走了,那么我们所求的就是dp[1][1] 開始的地方。所以解题的过程。就是一个逆推的过程。
以下,我们用两种视角(来解决本题)
代码:
首先以我们的视角:
#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
double dp[100][100];
int n;
double a,b,c,d,e; int main()
{
while(cin>>n&&n)
{
cin>>a>>b>>c>>d>>e;
memset(dp,0,sizeof(dp));
dp[n][1]=0;
for(int i=2;i<=n;i++)
dp[n][i]+=1*(dp[n][i-1]+1);//处理最后一行
for(int i=n-1;i>=1;i--)//从倒数第二行開始处理
{
dp[i][1]+=a*(dp[i+1][1]+1)+b*(dp[i+1][2]+1);//处理每一行的第一列
for(int j=2;j<=n;j++)
dp[i][j]+=c*(dp[i+1][j]+1)+d*(dp[i+1][j+1]+1)+e*(dp[i][j-1]+1);//处理每一行的除了第一列以外的其他列
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<dp[1][1]<<endl;
}
return 0;
}
以故事中主人公的视角:
#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
double dp[100][100];
int n;
double a,b,c,d,e; int main()
{
while(cin>>n&&n)
{
cin>>a>>b>>c>>d>>e;
memset(dp,0,sizeof(dp));
dp[n][n]=0;//目的地
for(int i=n-1;i>=1;i--)
dp[n][i]+=1*(dp[n][i+1]+1);
for(int i=n-1;i>=1;i--)//行数
{
dp[i][i]+=a*(dp[i+1][i+1]+1)+b*(dp[i+1][i]+1);
for(int j=i-1;j>=1;j--)
dp[i][j]+=c*(dp[i+1][j+1]+1)+d*(dp[i+1][j]+1)+e*(dp[i][j+1]+1);
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<dp[1][1]<<endl;
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
[2013山东ACM]省赛 The number of steps (可能DP,数学期望)的更多相关文章
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- The number of steps(概率dp)
Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
- [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...
- [2011山东ACM省赛] Sequence (动态规划)
Sequence Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Given an integer number sequence ...
- 2013年ACM湖南省赛总结
今年的比赛最大的变化就是改用OJ判题了,相比于PC^2确实省事了不少,至少可以直接复制样例了.题目方面依旧是刘汝佳命题,这点还是相当好的,至少给人以足够的安全感. 开始比赛之后安叔瞬间就把前半部分题目 ...
- [2011山东ACM省赛] Identifiers(模拟)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Identifier is an important ...
- [2011山东ACM省赛] Mathman Bank(模拟题)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/24187925 Mathman Bank ni ...
- 山东ACM省赛历届入口
山东省第一届ACM大学生程序设计竞赛 山东省第二届ACM大学生程序设计竞赛 山东省第三届ACM大学生程序设计竞赛 山东省第四届ACM大学生程序设计竞赛 山东省第五届ACM大学生程序设计竞赛 山东省第六 ...
随机推荐
- java.nio分析软件包(三)---Charset理解力
前面的分析后,2一个基本的封装类型.现在我们就来揭开Java.nio魔法知识的最后一块,CharsetEncoding类,他的主要功能是实现字节Unicode之间的转换转码. 让我们来看看他同样的封装 ...
- [原创] linux 下上传 datapoint数据到yeelink 【golang版本】
package main /* Create by sndnvaps<sndnvaps@gmail.com> * date : 2015-04-05 * upload datapoint ...
- 客户端上显示csdn上的各类别下的的文章列表 (制作csdn app 三)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/23597229 今天将在Android 使用Fragment,ViewPagerI ...
- CareerCup它1.8 串移包括问题
[称号] 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another ...
- [勘探开发]成绩,全栈开发,健全&借贷
开发探索的一些update: 将结果做为开发的基础和终极目标 开发人员从过程的追求到最后结果的追求是一个质变的过程.相当于NBA中得分王和总冠军的差别: 一个是完毕一个局部的本职工作(有时候会和项目的 ...
- MongoDB学习笔记-维护
主从复制 MongoDB有主从复制技术,解决高可用和容灾问题,也就是备份. 配置主从的特点: N 个节点的集群 任何节点可作为主节点 所有写入操作都在主节点上 自动故障转移 自动恢复 数据分布式存储 ...
- ezjailserver备份和恢复方法
FreeBSD通过使用ezjail管理jails虚拟机非常方便.公司有多台ezjailsserver,执行n许多jails虚拟机,硬盘故障,做一个整体恢复.感性的方法如以下: 备份就绪: 暗示ezja ...
- 【转】static_cast和reinterpret_cast
static_cast和reinterpret_cast揭秘 收藏 本文讨论static_cast<> 和 reinterpret_cast<>. reinterpret_ca ...
- Chrome console(转)
阅读目录 写在前面 谷歌控制台Elements面板 查看元素上绑定的事情 样式操作 总况 console.log console.info console.error console.warn con ...
- 带项目的一些体会以及合格的 Leader 应该具备什么特质?(转)
许多项目有这样几种 Leader: 1. 泛泛而谈型 很多时候 Leader 仅仅给出一个大方向,提一些高屋建瓴的理论方向,事情还是交由普通开发人员去做.完了可能又会回头埋怨开发人员的水平不行,没有达 ...