hdu 4405 Aeroplane chess(概率dp)
来源:互联网 发布:网络教育统考课程 编辑:程序博客网 时间:2024/05/03 08:26
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4405
解题思路:
题目大意: 并排的0~n的格子,起始点在0,每次向前走时都要掷骰子1~6,得到x,之后往前走x步,还有一些特殊的连接xi,yi, 如果到达xi就直接跳到yi不用掷骰子,求到达>=n掷骰子的次数的期望。
算法思想:
求概率正推,求期望反推。
式子很明显,E(w) 表示当前在w这个格子要达到条件(>=n)掷骰子次数的期望
如果存在(xi, yi),使得 w == xi, 则E(w) = E(yi) , 否则E(w) = ∑(E(w+i)/6) + 1 ,i从1到6
之后从后往前递推即可,答案就是E(0).
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <algorithm>using namespace std;map<int,int> mm;double dp[100005];int main(){ int n,m; while(~scanf("%d%d",&n,&m),n+m){ mm.clear(); int x,y; for(int i = 0; i < m; i++){ scanf("%d%d",&x,&y); mm[x] = y; } memset(dp,0,sizeof(dp)); for(int i = n-1; i >= 0; i--){ if(mm[i]) dp[i] = dp[mm[i]];//走捷径 else{ for(int j = 1; j <= 6; j++) dp[i] += 1.0/6*(dp[i+j]+1);//到达i的状态是由(i+1....i+6)来的 } } printf("%.4lf\n",dp[0]); } return 0;}
0 0
- hdu 4405 Aeroplane chess(概率dp)
- HDU 4405 Aeroplane chess (概率dp)
- hdu 4405 Aeroplane chess (概率dp)
- hdu 4405 Aeroplane chess(概率dp)
- hdu 4405 Aeroplane chess (概率DP)
- HDU 4405 Aeroplane chess(概率DP)
- HDU 4405 Aeroplane chess (概率dp)
- HDU 4405 Aeroplane chess (概率DP)
- hdu 4405 Aeroplane chess(概率dp)
- HDU 4405 Aeroplane chess(概率DP)
- HDU 4405 Aeroplane chess(概率DP)
- HDU-4405 Aeroplane chess (概率DP)
- HDU 4405 Aeroplane chess(概率dp)
- HDU 4405:Aeroplane chess(概率DP)
- HDU 4405 Aeroplane chess(概率DP)
- hdu 4405 Aeroplane chess 概率dp
- hdu 4405 Aeroplane chess(概率dp)
- HDU 4405 Aeroplane chess (概率dp)
- 阅读《21天学通Java》
- 数据库索引的实现原理
- mongo如何查看性能 debug
- iOS开发:通讯录之通讯录列表实现
- python 内置函数map、reduce的使用
- hdu 4405 Aeroplane chess(概率dp)
- hdu 4593 Robot
- 第18章(二)TCP状态变迁图与2MSL等待状态
- nginx机制详解
- 简单Latex
- java序列化
- django 1.8 官方文档翻译: 2-5-7 自定义查找
- Spring定时任务的几种实现
- AngularJS Hello World!