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 ...
随机推荐
- django 和 mysql的一次troubleshooting
下面是一次用django连接mysql的经历,记录下来也许以后会有帮助. 首先是用django的./manage.py syncdb 去连接mysql -bash-3.2$ ./manage.py s ...
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
Sometime we want to set a default or fallback value when network request failed. http$ .pipe( map(re ...
- JS推断是否为JSON对象及是否存在某字段
$.ajax({ type: 'POST', url: url, success(function(data){ //推断是否为JSON对象 if(typeof(data) == "obje ...
- RedisUtil: Jedis连接自动释放
package cloud.app.prod.home.utils; import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedi ...
- Codeforces Round #332 (Div. 2)A. Patrick and Shopping 水
A. Patrick and Shopping Today Patrick waits for a visit from his friend Spongebob. To prepare for ...
- jquery的ajax同步异步执行
大家先看一段简单的jquery ajax 返回值的js 代码 function getReturnAjax{ $.ajax({ type:"POST", http:/ ...
- Aviator
Aviator 简介¶ Aviator是一个高性能.轻量级的java语言实现的表达式求值引擎,主要用于各种表达式的动态求值.现在已经有很多开源可用的java表达式求值引擎,为什么还需要Avaitor呢 ...
- ubuntu Ngin Install
安装gcc g++的依赖库 #apt-get install build-essential #apt-get install libtool 安装 pcre依赖库 #sudo apt-get upd ...
- 修改Switch 的颜色
1:效果图 2:布局 <Switch android:id="@+id/switch_bg" style="@style/switchStyle" and ...
- Android 4.0 Launcher2源码分析——主布局文件(转)
本文来自http://blog.csdn.net/chenshaoyang0011 Android系统的一大特色是它拥有的桌面通知系统,不同于IOS的桌面管理,Android有一个桌面系统用于管理和展 ...