【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 ...
随机推荐
- Windows 10 (or 8)Chrome 观看视频发生flash不能加载,即"could't load plugins"原因之一
最近一直如题,不能看视频,后来发现从一个已经使用管理员权限打开的应用转到Chrome就可以加载flash,而从桌面打开Chrome就加载不了. 今天再次查找信息,从Ubuntu下Chrome不能加载f ...
- Window下配置NodeJs环境详解
今年打算学习Web这块,所以就买了本Node.js+MongoDb+AngularJS这本书,这周天也比较忙,想着录视频(拍小片,不是AV,不要误会,是在线课程)的事情,这周又将Asp.Net ...
- UI4_UIImageView
// // ViewController.m // UI4_UIImageView // // Created by zhangxueming on 15/7/1. // Copyright (c) ...
- 8个强大的基于Bootstrap的CSS框架
做过前端开发的小伙伴们应该对Bootstrap不会陌生,它是由Twitter推出的开源CSS框架,其中包含了很多Web前端开发的工具包和应用组件.当然,和jQuery一样,Bootstrap同时也是一 ...
- ROS ZYNQ移植
1 准备工作 全部是按照官方操作的:http://wiki.ros.org/groovy/Installation/Source apt-get install python-rosdep py ...
- ADO.NET笔记——将DataReader作为函数返回值
相关知识: 在很多情况下,可能把数据库的访问封装到一个函数中,通过该函数返回一个DataReader对象给调用者.例如定义函数:SqlDataReader returnDR(),然后再Main函数中调 ...
- Android 悬浮窗 WindowManager WindowManager.LayoutParamas
前方高清大图~~~~ 绘制的图片资源: // draw bitmap BitmapDrawable bmpDraw = (BitmapDrawable) getResources().getDrawa ...
- jquery插件开发模板
(function($){ $.fn.extend({ //将可选择的变量传递给方法 pluginname: function(options) { //设置默认值并用逗号隔开 var default ...
- NetworkInfo 手机中的网络类型
04-27 21:56:54.442: E/NetworkInfo(26457): NetworkInfo: type: mobile[EDGE], state: DISCONNECTED/IDLE, ...
- c# datatable list 相互转换
/*Converts List To DataTable*/ public static DataTable ToDataTable<TSource>(IList<TSource&g ...