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 ...
随机推荐
- iOS 时钟动画
在iOS开发中,定时器NSTimer并不能够准确的出发,通常使用NSTimer只能控制不需要精确处理的操作,而CADisplayLink就是在每次屏幕刷新时,通知系统.CADisplayLink最大的 ...
- Ubuntu 14.10 编译 qt4.8.6
0. 假设你已经可以在上面写基本的C++程序.(即:c/C++开发环境已经就绪)1. $ sudo apt-get build-dep libqt4-dev 2. $ sudo apt-get ins ...
- Javaweb统计在线人数的小栗子
最近在学习Javaweb相关的内容(不黑不吹之前对web开发零基础),下面通过一个统计在线人数的小栗子讲讲Servlet监听器吧 开发环境 eclipse tomcat 7 先说说这个小栗子的构思: ...
- BZOJ 2337: [HNOI2011]XOR和路径( 高斯消元 )
一位一位考虑异或结果, f(x)表示x->n异或值为1的概率, 列出式子然后高斯消元就行了 --------------------------------------------------- ...
- Hibernate学习之映射关系
一.Hibernate多对一关联映射:就是在“多”的一端加外键,指向“一”的一端. 比如多个学生对应一个班级,多个用户对应一个级别等等,都是多对一关系. 1.“多”端实体加入引用“一”端实体的变量及g ...
- poj 2398 计算几何
#include <iostream> #include<cstdio> #include<cstring> #include <algorithm> ...
- Lotus Sametime 服务器的安装和配置
IBM Lotus Sametime 是一款强大的实时协作软件,目前最新版本是 7.5.1.通过它,您不仅能够进行网络聊天,而且可以方便地召开网络会议.在网络社区中与其他人进行沟通.了解更多关于 Lo ...
- 分组求和SQL示例
1.ROLLUP和CUBE函数,自动汇总数据 select * from test_tbl的数据这样的 col_a col_b col_c ---- ----- ...
- php 前台数据显示
<pre name="code" class="html"> public function show(){ echo "访问了index ...
- HDU 2722 Here We Go(relians) Again
最短路,建图太麻烦,略过…… #include <cstdio> #include <cstring> #include <queue> const int INF ...