hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess
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.
Input
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.
Output
Sample Input
8 3
2 4
4 5
7 8
0 0
Sample Output
2.3441
Source
题意:
有一个飞行棋n个格子,刚开始在0这个位置,每次可以扔色子,扔到x则可以移动x格
如果到达的位置>=n则胜利
另外在棋盘上还有m对点x,y表示在位置x可以直接飞行到y
求到达胜利平均的扔色子次数
分析:
期望逆推。
d[i]表示到达 i 的时候还需要几次才能到达n。
初始d[n] = 0; 而d[0]就是所求的答案
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e5+;
using namespace std;
double d[maxn];
int c[maxn]; int main()
{
int n, m, i, j;
while(~scanf("%d%d", &n, &m))
{
if(n== && m==) break;
memset(c, -, sizeof(c));
for(i = ; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
c[a] = b;
}
memset(d, , sizeof(d));
d[n] = ;
double t = 1.0/;
for(i = n-; i >= ; i--)
{
if(c[i]==-)
d[i] += 1.0 + d[i+]*t + d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t;
else
d[i] = d[c[i]];
}
printf("%.4f\n", d[]);
}
return ;
}
hdu 4405 Aeroplane chess(简单概率dp 求期望)的更多相关文章
- HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
- 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 ...
- HDU-4405 Aeroplane chess(概率DP求期望)
题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...
- Aeroplane chess(简单概率dp)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
随机推荐
- Feature Engineering versus Feature Extraction: Game On!
Feature Engineering versus Feature Extraction: Game On! "Feature engineering" is a fancy t ...
- ASP.NET状态管理详解,让你明明白白
开发WinFrom的程序员可能不会在意维护应用程序的状态,因为WinFrom本身就在客户端运行,可以直接在内存中维护其应用程序状态.但ASP.NET应用程序在服务器端运行,客户端使用无状态的http协 ...
- 微信连WiFi关注公众号流程更新 解决ios微信扫描二维码不关注就能上网的问题
前几天鼓捣了一下微信连WiFi功能,设置还蛮简单的,但ytkah发现如果是ios版微信扫描微信连WiFi生成的二维码不用关注公众号就可以直接上网了,而安卓版需要关注公众号才能上网,这样就少了很多ios ...
- TKStudio 4.6IDE Warning: L6310W: Unable to find ARM libraries.
我也遇到了同样的问题.搞了很久,按下面的操解决了 内容转至:http://bbs.zlgmcu.com/dv_rss.asp?s=xh&boardid=43&id=23032& ...
- [C++]类的继承与派生
继承性是面向对象程序设计的第二大特性,它允许在既有类的基础上创建新类,新类可以继承既有类的数据成员和成员函数,可以添加自己特有的数据成员和成员函数,还可以对既有类中的成员函数重新定义.利用类的继承和派 ...
- C# 语音识别(文字to语音、语音to文字)
最近打算研究一下语音识别,但是发现网上很少有C#的完整代码,就把自己的学习心得放上来,和大家分享一下. 下载API: 1)SpeechSDK51.exe (67.0 ...
- 机器学习之多变量线性回归(Linear Regression with multiple variables)
1. Multiple features(多维特征) 在机器学习之单变量线性回归(Linear Regression with One Variable)我们提到过的线性回归中,我们只有一个单一特征量 ...
- SpringMVC学习总结(七)——SpringMVC注解@..详解
<context:component-scan/> 扫描指定的包中的类上的注解,常用的注解有: @Controller 声明Action组件@Service 声明Service组件 ...
- TableViewCell自定义分割线
产品设计的要求cell的分割线长度不用是整个屏幕宽,并且设计要求分割线为2px(两条),上下不同色. 实现如下: UITableView中将分割线样式改为None tableView.separato ...
- Fragment 的用法小技巧
public static class ArrayListFragment extends ListFragment { int mNum; /** * Create a new instance o ...