Code:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 100000 + 233;
const double perc = (1 / 6.0);
double f[maxn];
int vis[maxn];
int main()
{
int n,m;
while(1)
{
memset(vis, -1, sizeof(vis));
memset(f,0, sizeof(f));
scanf("%d%d",&n,&m);
if(!n) break;
for(int i = 1;i <= m; ++i)
{
int a,b;
scanf("%d%d",&a,&b);
vis[a] = b;
}
for(int i = n - 1;i >= 0;--i)
{
if(vis[i] != -1){ f[i] = f[vis[i]] ; continue; }
for(int j = 1;j <= 6; ++j) f[i] += (f[i + j] + 1) * perc;
}
printf("%.4lf\n",f[0]);
}
return 0;
}

  

Aeroplane chess HDU - 4405_数学期望_逆推的更多相关文章

  1. Codeforces Round #499 (Div. 2) C.FLY 数学推导_逆推

    本题应该是可以使用实数二分的,不过笔者一直未调出来,而且发现了一种更为优美的解法,那就是逆推. 首先,不难猜到在最优解中当飞船回到 111 号节点时油量一定为 000, 这就意味着减少的油量等于减少之 ...

  2. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  3. hdu 3853 LOOPS (概率dp 逆推求期望)

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  4. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  5. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  6. Aeroplane chess(HDU 4405)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. 【整理】简单的数学期望和概率DP

    数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...

  8. ZOJ3551Bloodsucker (数学期望)

    In 0th day, there are n-1 people and 1 bloodsucker. Every day, two and only two of them meet. Nothin ...

  9. hdu 4405 Aeroplane chess(简单概率dp 求期望)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. Python中对两种utf-8格式的理解

    1.python文件开头utf-8格式的理解 2.程序中读取文件时utf-8格式的理解 aa.py文件代码示例: #!/usr/bin/python # -*- coding:utf-8 -*- fr ...

  2. Automatic Tuning of Memory Management

    4.2.2 Automatic Tuning of Memory Management Two memory management initialization parameters, MEMORY_ ...

  3. RMAN主要命令 show,list,crosscheck,delete详解

    Oracle RMAN 的 show,list,crosscheck,delete命令整理  Oracle RMAN 的 show,list,crosscheck,delete命令整理 1.SHOW命 ...

  4. 为什么pthread_cond_wait须要传递mutex參数

    这是来自知乎的一个问题,由@吴志强提出,有意思的是,他看了大家的回答后,突然顿悟了,同一时候也发现有人答错了,于是乎.他自己回答了自己的问题. 我看完后.发现他分析的非常精彩,于是就记录在这.以下是他 ...

  5. 第14章3节《MonkeyRunner源代码剖析》 HierarchyViewer实现原理-HierarchyViewer实例化

    既然要使用HierarchyViewer来获取控件信息,那么首先我们看下在脚本中.我们是怎么获得HierarchyViewer的,看以下一段脚本代码: 1 device = MonkeyRunner. ...

  6. 2016.04.07,英语,《Vocabulary Builder》Unit 11

    cant, from the Latin verbs canere and cantare, meaning 'sing'. by way of French, add an h to the roo ...

  7. Android代码宏控制方案 【转】

    本文转载自:http://blog.sina.com.cn/s/blog_769500f001017ro6.html 目前107分支上,在各项目projectConfig.mk中已添加项目宏以及客户宏 ...

  8. Elo rating system(Elo 打分体系)

    A.B 两个待比较.评价的对象,分别打分为 RA,RB,则各自获胜的期望值为: ⎧⎩⎨⎪⎪⎪⎪⎪⎪EA=11+10(RB−RA)/400.EB=11+10(RA−RB)/400. 不妨令 QA=10R ...

  9. 2.2.3 修改JSX代码

    /** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { ...

  10. LINUX/UNIX找回删除的文件

    当Linux计算机受到入侵时,常见的情况是日志文件被删除,以掩盖攻击者的踪迹.管理错误也可能导致意外删除重要的文件,比如在清理旧日志时,意外地删除了数据库的活动事务日志.有时可以通过lsof来恢复这些 ...