传送门

期望dp简单题啊。

不过感觉题意不太对。

手过了一遍样例发现如果有捷径必须走。

这样的话就简单了啊。

设f[i]" role="presentation" style="position: relative;">f[i]f[i]表示从第i个格子出发到第n个格子的期望步数。

显然就可以从f[i+1]~f[i+6]转移过来了,注意如果f下标超过n期望步数都是0。

代码:

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,jump[N];
double f[N];
inline int read(){
    int ans=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
int main(){
    while(scanf("%d%d",&n,&m)){
        if(!n&&!m)break;
        memset(jump,0,sizeof(jump));
        for(int i=1;i<=m;++i){int u=read(),v=read();jump[u]=v;}
        f[n]=0;
        for(int i=n-1;~i;--i){
            f[i]=0;
            if(jump[i]){f[i]=f[jump[i]];continue;}
            for(int j=1;j<=6;++j){
                int k=min(i+j,n);
                f[i]+=f[k];
            }
            f[i]=f[i]/6.0+1;
        }
        printf("%.4lf\n",f[0]);
    }
    return 0;
}

2018.09.01 hdu4405 Aeroplane chess (期望dp)的更多相关文章

  1. HDU4405 Aeroplane chess(期望dp)

    题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 正在玩飞行棋.输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示 ...

  2. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  3. HDU 4405 Aeroplane chess 期望dp

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

  4. [hdu4405]Aeroplane chess(概率dp)

    题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...

  5. HDU4405 Aeroplane chess (概率DP,转移)

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...

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

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

  7. 2018.09.09 UVa10529 - Dumb Bones(期望dp)

    传送门 期望dp好题. f[i]表示摆放i个的最小花费,于是f[i]可以从f[j]与f[i-j+1]转移过来了. 代码: #include<bits/stdc++.h> #define N ...

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

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

  9. hdu4405 Aeroplane chess

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

随机推荐

  1. you boot volume has only 0 byte size

    懒人方法: uname -a 列出目前使用的内核 dpkg -l | grep linux-image 列出存在的linux内核 sudo apt-get purge linux-image-3.16 ...

  2. VC中使用ADO操作数据库的方法

    源地址:http://blog.csdn.net/xiaobai1593/article/details/7459862 准备工作: (1).引入ADO类 #import "c:\progr ...

  3. Python的isdigit()和isalpha()

    提供一个参考链接<isalpha() Method> 使用isdigit()判断是否是全数字: if  word.encode( 'UTF-8' ).isdigit() 使用isalpha ...

  4. scala -- 传名参数

    object Test{ def main(args: Array[String]): Unit = { def test(code : => Unit){// 传名参数 不计算函数值,而是把函 ...

  5. Hadoop 3.0.0-alpha1几个值得关注的特性

    1.支持纠删码:意味着更灵活的存储策略,即经常使用的数据利用备份方式存储(3倍存储消耗),冷数据利用纠删码容错(1.4倍存储消耗,但会造成额外的IO及CPU消耗): 2.MapReduce任务支持本地 ...

  6. tomcat 管理端 安全措施

    由于公司的项目并未启用nginx负载均衡,所以自然也没用到tomcat与web应用一对一的安全操作,经常会遇到 重启单个应用又不想重启tomcat的情况.同时,又出于安全考虑,将tomcat的默认管理 ...

  7. keynote

    [keynote] 1.如何保证文档加载完才运行代码? 2.元素选择器. 3.属性选择器. 4.更新css. 5.更复杂的例子. 6.常用事件. 7.hide & slow 8.您可以使用 t ...

  8. Hibernate实体映射转换列值

    @Column(name="ADDTIME", insertable=false, updatable=false)@ColumnTransformer(read="CA ...

  9. goim源码分析与二次开发-comet分析二

    这篇就是完全原版了,作为一个开始,先介绍comet入口文件main.go 第一步是初始化配置,还有白名单.还有性能监口,整体来说入口代码简洁可读性很强 然后开始初始化监控,还有bukcet这里buck ...

  10. Majority Element(ARRAY-BINARY SEARCH)

    QUESTION Given an array of size n, find the majority element. The majority element is the element th ...