HDU 4405 Aeroplane chess(概率dp,数学期望)
http://kicd.blog.163.com/blog/static/126961911200910168335852/
根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什么“是下一分钟,故要加上1.”?
好吧,先写着,有事没事想一想,也许时间长了就明白了。
别的人解释很棒:(虽然我还没全懂)
//e[i]表示i的位置走到n所需要的期望步数
//那么e[i]怎么求,首先e[i]走到e[i+1]的概率为1/6 ,
//而e[i+1]是走到终点的期望步数,所以e[i]=e[i+1]*1/6+1,
//为什么加一呢,因为你向前走了一步,期望表示的是步数
//以此类推 e[i]=1+e[i+1]*1/6+e[i+2]*1/6+e[i+3]*1/6...+e[i+6]*1/6
//CF 417 //e[i]表示i的位置走到n所需要的期望步数
//那么e[i]怎么求,首先e[i]走到e[i+1]的概率为1/6 ,
//而e[i+1]是走到终点的期望步数,所以e[i]=e[i+1]*1/6+1,
//为什么加一呢,因为你向前走了一步,期望表示的是步数
//以此类推 e[i]=1+e[i+1]*1/6+e[i+2]*1/6+e[i+3]*1/6...+e[i+6]*1/6 #include <stdio.h>
#include <string.h>
#include<algorithm>
#include<string>
using namespace std;
int mp[];
double e[];
int main()
{ int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
memset(mp,,sizeof(mp));
for(int i=;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x]=y;
}
memset(e,,sizeof(e));
for(int i=n-;i>=;i--)//因为e[n]=0,所以不用再处理它了
{
if(mp[i])e[i]=e[mp[i]];
else
{
for(int j=;j<=;j++)
e[i]+=(1.0/6.0*e[i+j]);
e[i]+=1.0;
}
}
printf("%.4lf\n",e[]);
}
return ;
}
HDU 4405 Aeroplane chess(概率dp,数学期望)的更多相关文章
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
- HDU4405-Aeroplane chess(概率DP求期望)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
随机推荐
- 开源GIS软件 4
空间数据操作框架 Apache SIS Apache SIS 是一个空间的框架,可以更好地搜索,数据聚类,归档,或任何其他相关的空间坐标表示的需要. kvwmap kvwmap是一个采用PHP开发的W ...
- HDU 2767-Proving Equivalences(强联通+缩点)
题目地址:pid=2767">HDU 2767 题意:给一张有向图.求最少加几条边使这个图强连通. 思路:先求这张图的强连通分量.假设为1.则输出0(证明该图不须要加边已经是强连通的了 ...
- Linux模块化机制和module_init
致谢: 微信公众号:嵌入式企鹅圈 每天都新增爱好者关注,感谢大家的支持和大牛们的建议. 本人将竭力出品很多其它优质的原创文章回馈大家的厚爱. 引子:模块化机制长处 模块化机制(module)是Linu ...
- Android动态逆向分析工具ZjDroid--脱壳神器
项目地址:https://github.com/BaiduSecurityLabs/ZjDroid 前提条件: 1.Root手机一部 2.须要通过Xposed installer( http://dl ...
- oc54--auatorelease应用场景
// // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject @property (nonat ...
- Realm Update failed - Android
Realm Update failed - Android Ask Question up vote 0 down vote favorite I'm using realm for my andro ...
- alsa 用户空间编程【转】
本文转载自:http://blog.csdn.net/sjin_1314/article/details/12872581 /**alsa play test *ALSA用户空间编译,ALSA驱动的声 ...
- 阻塞、非阻塞、同步、异步IO
阻塞.非阻塞.同步.异步IO http://www.cnblogs.com/yunxitalk/p/9031306.html 介绍 在谈及网络IO的时候总避不开阻塞.非阻塞.同步.异步.IO多路复用. ...
- 洛谷 P3112 后卫马克 —— 状压DP
题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...
- layui富文本编译器添加图片
1.创建富文本编辑器 <form class="layui-form" method="post" id="myForm" encty ...