HDU4405 Aeroplane chess(期望dp)
题意
抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html
正在玩飞行棋。输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示u点可以直接飞向v点,即u为飞行点。如果格子不是飞行点,扔骰子(1~6等概率)前进。否则直接飞到目标点。每个格子是唯一的飞行起点,但不是唯一的飞行终点。问到达或越过终点的扔骰子期望数。
从0出发!!
Sol
比较zz的期望dp
设$f[i]$表示从$i$出发,到达$n$的期望步数
转移的时候讨论一下即可
/* */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 1e5 + , INF = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M, to[MAXN];
double f[MAXN];
int main() {
while(scanf("%d %d", &N, &M)) {
if((N == ) && (M == )) break;
memset(to, , sizeof(to));
memset(f, , sizeof(f));
for(int i = ; i <= M; i++) {
int x = read(), y = read();
to[x] = y;
}
for(int x = N - ; x >= ; x--) {
if(to[x]) f[x] = f[to[x]];
else {
for(int j = ; j <= ; j++) f[x] += f[x + j];
f[x] /= ; f[x]++;
}
}
printf("%.4lf\n", f[]);
}
return ;
}
/* */
HDU4405 Aeroplane chess(期望dp)的更多相关文章
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- [hdu4405]Aeroplane chess(概率dp)
题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...
- HDU4405 Aeroplane chess (概率DP,转移)
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...
- 2018.09.01 hdu4405 Aeroplane chess (期望dp)
传送门 期望dp简单题啊. 不过感觉题意不太对. 手过了一遍样例发现如果有捷径必须走. 这样的话就简单了啊. 设f[i]" role="presentation" sty ...
- HDU4405 Aeroplane chess 飞行棋 期望dp 简单
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:问从起点到终点需要步数的期望,1/6的概率走1.2.3.4.5.6步.有的点a有路可以直接到b, ...
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU-4405 Aeroplane chess
http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...
随机推荐
- 如何使用 Jmeter 发送 Json 请求
公司最近有一个项目,需要持续发送大量的 Json 请求到服务器,从而测试服务器可靠性. 我就发送 Json 请求部分发布这个博客. 一般来说, Json 请求的数据都保存到 CSV 文件中,然后使用 ...
- poj1151 Atlantis——扫描线+线段树
题目:http://poj.org/problem?id=1151 经典的扫描线问题: 可以用线段树的每个点代表横向被矩形上下边分割开的每一格,这样将一个矩形的出现或消失化为线段树上的单点修改: 每个 ...
- Linux下共享库嵌套依赖问题 (转载)
转自:http://my.oschina.net/moooofly/blog/506466 问题场景: 动态库 librabbitmq_r.so 内部依赖动态库 libevent_core.so 和 ...
- .net 反射构造你自己的“匿名”对象
由于近来项目的底层架构某些特殊需求及场景的需要要求动态build一个对象, 属性名称个类与类型都是外界动态传入的. 不多说废话,直接上我最原始的代码: public static Type GetMy ...
- vue仿淘宝地址选择组件
Vue组件:省市区地址选择组件 <template> <div v-show="addressSelectShow" :style="{'left': ...
- SourceTree配置BeyondCompare代码冲突解决工具
一.工具准备:SourceTree这个你得有.然后下载BeyondCompare(破解教程) 二.配置环境:SourceTree->工具->选项->比较,外部对比工具和合并工具都选择 ...
- CodeForces 761C 【DP】
总结:能这么DP就这么写! 多练位运算标记. #include<bits/stdc++.h> using namespace::std; const int N=55; const int ...
- lightoj 1076 【二分找满足条件的最左】
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...
- lightoj 1089 【离散化+线段树】
题意: 给你n个区间,然后给你m个i点问你这个点在几个所给定的区间里: 思路: 离散化+区间覆盖 #include <bits/stdc++.h> using namespace std; ...
- 五分钟了解Mecanim角色动画系统
http://www.narkii.com/club/thread-305414-1.html Unity 4.0推出的Mecanim动画系统已经有一段时间,不过据了解很多的朋友仍然在使用原来的角色动 ...