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 ...
随机推荐
- 自己写spring boot starter
自己写spring boot starter 学习了:<spring boot实战>汪云飞著 6.5.4节 pom.xml <project xmlns="http://m ...
- requireJS使用shim注入非标准模块详解
在javascript中定义全局变量有2种方式,本质上是等价的,都是向window对象注入属性或者方法. // global.js var g_name = "aty"; wind ...
- luogu2765 魔术球问题 网络流
题目大意: 假设有n根柱子,现要按下述规则在这n根柱子中依次放入编号为1,2,3,...的球.(1)每次只能在某根柱子的最上面放球.(2)在同一根柱子中,任何2个相邻球的编号之和为完全平方数.试设计一 ...
- Codeforces--621B--Wet Shark and Bishops(数学)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...
- B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...
- 0509 关于Ajax + 三级联动示例
关于Ajax 1.干什么的? ajax负责抓取用户名信息,传递给服务器进行校验: 2.属性: onreadystatechange:事件,该事件可以感知ajax状态(readyState)的变化.aj ...
- Appium + python - automator定位升级版操作
# coding:utf-8 """参考博客链接:https://www.cnblogs.com/yoyoketang/p/7843819.html"" ...
- python实践
https://www.cnblogs.com/smallSevens/p/10016045.html --二手房交易记录 https://www.cnblogs.com/xiangyuecn/p/1 ...
- python2.X现在不能安装Django了:Collecting django Using cached Django-2.0.tar.gz
使用pip安装django2: pip install django 报错: Collecting django Using cached Django-2.0.tar.gz Complete ...
- Elasticsearch之curl删除索引库
关于curl创建索引库的介绍,请移步 Elasticsearch之curl创建索引库 [hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://1 ...