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 ...
随机推荐
- 幻世(OurDream)TM 2D图形引擎开通捐赠渠道
为了支持幻世(OurDream)TM 2D图形引擎更好的发展,同一时候也是为了给希望支持引擎发展的朋友一个安全快捷的渠道,Lizcst Software Lab于今日正式在官方旗舰店增设了一个捐赠捐款 ...
- js面试题--------JS中数字和字符,布尔类型相加相减问题
JS中数字和字符相加相减问题 <html lang="en"> <head> <meta charset="utf-8" /> ...
- hdu 4941 Magical Forest (map容器)
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calcula ...
- Git是什么?
Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! 那什么是版本控制系统? 如果你用Microsoft Word写过长篇大论,那你一定有这样的 ...
- hihocoder 1676 树上等差数列 黑科技树形dp
#1676 : 树上的等差数列 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵包含N个节点的无根树,节点编号1~N.其中每个节点都具有一个权值,第i个节点的权值 ...
- SPOJ GSS 系列
来怒做GSS系列了: GSS1:https://www.luogu.org/problemnew/show/SP1043 这题就是维护一个 sum , mx , lmx , rmx,转移时用结构体就好 ...
- C Looooops(扩展欧几里得+模线性方程)
http://poj.org/problem?id=2115 题意:给出A,B,C和k(k表示变量是在k位机下的无符号整数),判断循环次数,不能终止输出"FOREVER". 即转化 ...
- Redis(二)-Win系统下安装
下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情况选择,这里我们下载 Red ...
- HDU 1166 线段树模板&树状数组模板
HDU1166 上好的线段树模板&&树状数组模板 自己写的第一棵线段树&第一棵树状数组 莫名的兴奋 线段树: #include <cstdio> using nam ...