【HDOJ】【4405】Aeroplane chess飞行棋
概率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飞行棋的更多相关文章
- HDU4405 Aeroplane chess 飞行棋 期望dp 简单
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:问从起点到终点需要步数的期望,1/6的概率走1.2.3.4.5.6步.有的点a有路可以直接到b, ...
- 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
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
- HDU 4405 Aeroplane chess:期望dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a ...
- 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 ...
- [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求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
随机推荐
- 桌面虚拟化之XenDesktop7
安装篇 1. 安装所需要的组件 2. 安装核心组件 配置篇 完整的部署 1. 打开Citrix Studio软件 2. 选择完整部署 3. 创建站点 4. 选择数据库(可以使用自己的或者默认使用自带的 ...
- Collection 和 Collections的区别。
Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...
- 让人心动的jQuery插件和HTML5动画
1.jQuery/CSS3带表单的下拉菜单 今天要分享一款基于jQuery和CSS3的下拉菜单,这款jQuery下拉菜单非常特别,我们直接可以在下拉菜单中填写联系表单.登录表单.而且整个下拉菜单的外观 ...
- 《锋利的jQuery》心得笔记--Two Sections
第三章 1. DOM操作(节点) 1) 查找节点可以查找元素节点和属性节点 2) 创建节点: (1) 创建元素节点 var addLi = $(“&l ...
- 纪念一下自己的第一篇cnblog
2016-08-1016:33:22 // Netease.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iost ...
- 安装Java EE失败,解决方案
笔者安装Java EE(版本是java_ee_sdk-7-jdk7-windows-x64-ml.exe)时,遇到错误提示提示"Could not find the required ver ...
- java8个基本类型和它们所占的字节数
byte : 1字节 short : 2字节 int : 4字节 float :4字节 long : 8字节 double : 8字节 char :2字节 boolean : 1字节 补充说明:在实际 ...
- iOS获取汉字的拼音
在iOS开发中经常涉及到汉字的排序,最常见的就是需要根据首字母的字符顺序排列,比如常见的通讯录等.总结出来,大致可以分为两种方法,其中参考文献[1]中提供的方法十分复杂,利用查表的方法是先,并且代码量 ...
- Factory_Method
class Product { public: virtual ~Product() {} ; }; class ProductA : public Product { public: Product ...
- linux查看硬件信息
1,查看CPU信息:cat /proc/cpuinfo2,查看板卡信息:cat /proc/pci3,查看USB设备:cat /proc/bus/usb/devices4,查看PCI信息:lspci ...