http://acm.hdu.edu.cn/showproblem.php?pid=4405

明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优

设E[i]为分数为i时还需要走的步数期望,j为某个可能投出的点数如果从i向i-j推导,我们并不能确定i的转移方向,因为可能有两个i-j有飞机其目的地是i,所以我们选择从i向i+j推导期望

如果设G[i]为分数为i时已经走过的步数期望,那么要确定G[i+j]需要知道P(i|i+j),也即转移到i+j的条件下从i转移来的概率,比较麻烦

由题意,设match[i]为i处飞机的目的地,则当match[i]存在时,E[i]=E[match[i]],否则E[i]=sigma((E[i+j]+1)*(1/6)),j in range(6)

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
double e[maxn];
int match[maxn];
int n,m;
void init()
{
memset(e,0,sizeof(e));
memset(match,0,sizeof(match));
for(int i=0;i<m;i++){
int f,t;
scanf("%d%d",&f,&t);
match[f]=t;
}
}
int lt(int a){return min(a,n);}
void calc()
{
for(int i=n-1; i>=0; i--)
{
if(match[i]!=0)e[i]=e[lt(match[i])];
else
{
for(int j=1; j<=6; j++)
{
e[i]+=(e[lt(i+j)]+1)/6;
}
}
}
}
int main()
{
for(int ti=1; scanf("%d%d",&n,&m)==2&&(n||m); ti++)
{
init();
calc();
printf("%.4f\n",e[0]);
} return 0;
}

HDU 4405 Aeroplane chess 概率DP 难度:0的更多相关文章

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

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

  2. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  3. HDU 4405 Aeroplane chess(概率dp,数学期望)

    题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...

  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)

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

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

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

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

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

  8. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  9. 【刷题】HDU 4405 Aeroplane chess

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

随机推荐

  1. HTML5探索之datalist研究

    最近一个项目需要用到类似淘宝,百度搜索时的自动检索方案.自然想到了使用datalist标签.但是遇到一个bug,经过两天研究.小有结果给大家分享下~~ 首先看bug吧!~ 因为项目最开始测试就是用36 ...

  2. 5.7 C和C++的关系

  3. [js] 有趣的js面试题,你答对了吗?

    题目1: 回答以下代码,alert的值分别是多少?

  4. IE6 + png24 透明图片(滤镜)

    IE6 + png24 透明图片(滤镜) .IE6png{_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true ...

  5. 堆排序(C语言)

    #ifndef HEAP_SORT_H #define HEAP_SROT_H #include<iostream> void maxHeap(int *arr,unsigned int ...

  6. fushioncharts的使用教程

    FusionCharts 是使用javascript 实现统计图表的js组件:其官网地址:http://www.fusioncharts.com.其早期版本FusionCharts Free 是基于f ...

  7. Form1和Form2的交互

    比如在第二个窗体中操作第一个窗体中的TreeView,动态添加节点和子节点. ------回答--------- ------其他回答(20分)--------- 尽量不要这样做.控件,窗体,你在.n ...

  8. python 练习 6

    #!/usr/bin/python # -*- coding: utf-8 -*- from collections import deque from math import log10 def p ...

  9. Ubuntu 14.04 分区方案

    我磁盘大概还有70多G的空间吧,我全部拿来使用的.真实的双系统哦. 一般来讲,linux系统分区最少要包括/和/swap两个.这样据说会影响性能,没有这样安装过,就无从考证啦.其实就是重装系统的时候, ...

  10. 在ArcMap 10.3中创建和编辑数据

    在ArcMap 10.3中创建和编辑数据 .......待补充 新建 创建一个新文件((Points, Polylines, and Polygons/点.线.多边形)