hdu4405概率dp入门
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1122 Accepted Submission(s): 762
at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.
There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is
no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
2 0
8 3
2 4
4 5
7 8
0 0
1.1667
2.3441
/*题意:有一个飞行棋n个格子,刚開始在0这个位置,每次能够扔色子,扔到x则能够移动x格
假设到达的位置>=n则胜利
另外在棋盘上还有m对点x,y表示在位置x能够直接飞行到y
求到达胜利平均的扔色子次数 分析:求期望,假设dp[i]表示在点i位置到达胜利所须要的平均次数,则我们须要求dp[0]
dp[n],dp[n+1]....等是知道的:为0
而对于dp[i]能够到达:
假设点i不能飞行:dp[i+1],dp[i+2],dp[i+3],dp[i+4],dp[i+5],dp[i+6]且等概率:1/6
假设i点位置能够飞行则能够到达飞行的点
由E(aA+bB+cC+dD...)=aEA+bEB+....
可知:dp[i]=1/6*dp[i+1]+1/6*dp[i+2]...
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef long long LL;
using namespace std; const int MAX=100000+10;
int n,m,size;
int head[MAX];
double dp[MAX];//dp[i]表示从i到达目标所须要的平均次数(期望) struct Node{
int y,next;
Node(){}
Node(int Y,int NEXT):y(Y),next(NEXT){}
}node[MAX]; void Init(){
memset(head,-1,sizeof head);
memset(dp,0,sizeof dp);
size=0;
} void InsertNode(int x,int y){
node[size]=Node(y,head[x]);
head[x]=size++;
} double Solve(int x){
double sum=0,num=0;
for(int i=head[x];i != -1;i=node[i].next){
sum+=dp[node[i].y];
++num;
}
return sum/num;
} int main(){
int x,y;
while(~scanf("%d%d",&n,&m),n+m){
Init();
for(int i=0;i<m;++i){
scanf("%d%d",&x,&y);
InsertNode(x,y);
}
for(int i=n-1;i>=0;--i){
if(head[i] != -1){
dp[i]=Solve(i);
}else{
dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6+1;
}
}
printf("%.4lf\n",dp[0]);
}
return 0;
}
hdu4405概率dp入门的更多相关文章
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
- 概率DP入门学习QAQ
emmmm博客很多都烂尾了...但是没空写..先写一下正在学的东西好了 概率DP这东西每次考到都不会..听题解也是一脸懵逼..所以决定学习一下这个东东..毕竟NOIP考过...比什么平衡树实在多了QA ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- 洛谷P2719 搞笑世界杯 题解 概率DP入门
作者:zifeiy 标签:概率DP 题目链接:https://www.luogu.org/problem/P2719 我们设 f[n][m] 用于表示还剩下n张A类票m张B类票时最后两张票相同的概率, ...
- POJ 2096-Collecting Bugs(概率dp入门)
题意: 有n种bug和s种系统bug,每天发现一种bug(可能已经发现过了)所有种bug被发现的概率相同,求所有bug被发现的期望天数. 分析: dp[i][j]发现i种bug,j种系统bug期望天数 ...
- HDU 3853-loop(概率dp入门)
题意: r*c个方格,从(1,1)开始在每个方格可释放魔法(消耗能量2)以知,释放魔法后可能在原地.可能到达相邻的下面格子或右面格子,给出三者的概率 求要到达(R,C)格子,要消耗能量的期望值. 分析 ...
- hdu3853之概率dp入门
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xingyeyongheng/article/details/25205693 LOOPS Time ...
随机推荐
- 新手不得不注意HTML CSS 规范
作为一名新进的程序菜鸟,根本不知道从哪里开始学起好,前辈都说HTML CSS 规范是一个十分需要注意的点,要我记下,特地转来保存一下,大家相互学习 //总论 本规范既然一个开发规范,也是一个脚本语言参 ...
- js执行环境相关
Js执行过程 如果一个文档中存在多个代码段 步骤一:读入第一个代码段(js引擎并非一行一行执行,而是一段一段分析执行) 步骤二:做词法分析和语法分析,有错则报语法错误(比如括号不匹配等),并跳转到步骤 ...
- SQLHelper简单版(基础版)
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- 两个textarea 同时变化高度
<html><head><script type="text/javascript" src="/jquery/jquery.js" ...
- C#复习三(Day 22)
哈哈,又到了总结的时间了.今天还是在继续复习C#的基础语法.这次总结主要以一下小程序为主. Split()的运用 123-456---789-----123-2把类似的字符串中重复符号去掉,得到123 ...
- BZOJ 1191: [HNOI2006]超级英雄Hero(二分图匹配)
云神说他二分图匹配从来都是用网络流水过去的...我要发扬他的精神.. 这道题明显是二分图匹配.网络流的话可以二分答案+最大流.虽然跑得很慢.... -------------------------- ...
- bzoj 1857: [Scoi2010]传送带 三分
题目链接 1857: [Scoi2010]传送带 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 934 Solved: 501[Submit][Stat ...
- 关于Python中的yield(转载)
您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ? 我们先抛开 generator,以一个常见的编程题目来展示 yield ...
- access数据库 top语句失效解决方法
使用查询语句 select top 1 * from News order by [PublicTime] desc 就不一定管用了,如果News表里面的PublicTime字段 ...
- python的Error集,17个新手常见Python运行时错误
python及相关工具安装Error集 . 如果升级python版本中出现error .so.1.0: cannot open shared object file: No such file or ...