概率DP/数学期望

  kuangbin总结中的第4题

  啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……)

  好像有点感觉了……

  首先不考虑直飞的情况:

    f[i]表示从第 i 格到end的期望掷骰子次数,那明显就是从f[i+1]~f[i+6]各1/6的概率(系数) 转移过来啦~

  那直飞呢?

    so easy,f[i]=f[fly[i]]即可,其中fly[i]表示从第 i 格飞到的格子。当然直飞就不用再考虑1/6的掷骰子情况了……

  从n-1往0逆推即可

P.S.多组数据记得清空数组哦~不要偷懒……那样容易出错的……

 //HDOJ 4405
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e5+,INF=~0u>>;
/*******************template********************/
const double p0=1.0/;
double f[N];
int fly[N]; int main(){
// freopen("input.txt","r",stdin);
int n,m,x,y;
while(scanf("%d%d",&n,&m)!=EOF && n){
memset(fly,,sizeof fly);
memset(f,,sizeof f);
F(i,,n+) fly[i]=;
F(i,,m){
x=getint(); y=getint();
fly[x]=y;
}
D(i,n-,){
f[i]=;
if (fly[i]) f[i]=f[fly[i]];
else F(j,,) f[i]+=p0*f[i+j];
}
printf("%.4lf\n",f[]);
}
return ;
}

【HDOJ】【4405】Aeroplane chess飞行棋的更多相关文章

  1. HDU4405 Aeroplane chess 飞行棋 期望dp 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=4405   题意:问从起点到终点需要步数的期望,1/6的概率走1.2.3.4.5.6步.有的点a有路可以直接到b, ...

  2. HDU 4405 Aeroplane chess 期望dp

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

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

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

  4. 【刷题】HDU 4405 Aeroplane chess

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...

  5. HDU 4405 Aeroplane chess:期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a ...

  6. hdu 4405 Aeroplane chess (概率DP)

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

  7. hdu 4405 Aeroplane chess(概率+dp)

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...

  8. [ACM] hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...

  9. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

随机推荐

  1. MVC 增加手机站

    首先在全局路由(RouteConfig)中加入以下图片中的代码.

  2. 4月12日学习笔记——jQuery事件

    下面是在 jQuery 中最常使用的 bind()方法举例:$("#testDiv4").bind("click", showMsg); 我们为 id 是 te ...

  3. 10款强大的jQuery/HTML5应用新鲜出炉

    1.CSS3/jQuery自定义弹出窗口 多种弹出动画 这是一款利用jQuery和CSS3实现的自定义弹出窗口,这可比浏览器默认的弹出窗口漂亮多了.弹出窗口中可以自定义html,十分灵活.另外最重要的 ...

  4. Linux相关指令

    Linux相关指令 1.find文件搜索功能 find [目录列表] [匹配参数] [匹配标准] -name :按文件名称进行搜索 -group :按文件所属组进行搜索 -user :按文件拥有者进行 ...

  5. linux kernel with param

    Linux kernel support pass param to kernel, this params can be assigned at load time by insmod or mod ...

  6. C++ 实现不能被继承的类

    方法一: #include <iostream> using namespace std; class A { public: static A* getInstance(); stati ...

  7. Excel 窗体控件属性

    常规 AutoLoad   (Excel) 打开工作簿时是否加载控件.(如果是 ActiveX   控件,则忽略.) Enabled(表单) 控件是否可以接收焦点并响应用户生成的事件. Locked( ...

  8. windows通过thrift访问hdfs

    thirift是一个支持跨种语言的远程调用框架,通过thrift远程调用框架,结合hadoop1.x中的thriftfs,编写了一个针对hadoop2.x的thriftfs,供外部程序调用. 1.准备 ...

  9. Log4Net总结

    Log4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方(文件.数据库.EventLog等),日志就是程序的黑匣子,可以通过日志查看系统的运行过程,从而发现系统的问题.日志的作用:将运 ...

  10. 转: js操作cookie

    cookie的几个概念 http://dearhappyfish.blog.163.com/blog/static/1901094152012422114753777/ js操作cookie 转:ht ...