【期望dp】hdu 4405 Aeroplane chess
来源:互联网 发布:乌克兰男女比例知乎 编辑:程序博客网 时间:2024/05/29 11:42
http://acm.hdu.edu.cn/showproblem.php?pid=4405
第2道概率期望dp,状态转移很好想,入门题目。
/* hdu 4405 期望DP 仍然是倒着递推题意: 飞行棋,从1-n,每次走的步数掷筛子决定,问到达终点走的总步数的期望求解: dp[i]表示已经到位置i最终到达终点的期望 dp[i] = sigma ((1/6.0) * dp[i+k] ) + 1,k = 1,2,3,4,5,6 如果遇到飞行的情况,dp[i] = dp[j] map离散化一下可以,状态转移方程好想*/ #include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<vector>#include<set>#include<map>#include<algorithm>#include<sstream>#define eps 1e-9#define pi acos(-1)#define long long ll#define M 10#define N 1010using namespace std;const int _max = 1e5 + 10;int n,m,u,v;double dp[_max];map<int,int>mp;int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE while(scanf("%d%d",&n,&m)==2&&n+m){ mp.clear(); for(int i = 0; i < m; ++ i){ scanf("%d%d",&u,&v); mp[u] = v; } dp[n] = 0;//dp[i]表示已经到达位置i,再到最终目标的期望;最终求解dp[0] memset(dp,0,sizeof(dp)); for(int i = n-1; i >= 0;i -- ){ if(!mp[i]){ for(int j = 1; j <= 6; ++ j) dp[i]+=dp[(i+j>n)?n:i+j]/6.0; dp[i]+=1; } else dp[i] = dp[mp[i]]; } printf("%.4f\n",dp[0]); } return 0;}
0 0
- hdu 4405 Aeroplane chess (期望dp)
- HDU 4405 Aeroplane chess(期望DP)
- hdu oj 4405 Aeroplane chess dp+期望
- 【期望dp】hdu 4405 Aeroplane chess
- [hdu 4405] Aeroplane chess [概率DP & 期望]
- [HDU] 4405 Aeroplane chess 期望dp入门
- Hdu 4405 Aeroplane chess DP求期望
- hdu 4405 Aeroplane chess(期望)
- hdu 4405 Aeroplane chess(很水的期望DP)
- HDU 4405 Aeroplane chess 概率dp求期望
- HDU 4405 Aeroplane chess (DP求期望) #by Plato
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- 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 基础题
- linux之sort用法
- TCP与UDP的应用
- 关于linux下 gcc 编译时for循环的报错。c99
- 【日程表】
- FZU 2203 单纵大法好 (二分+贪心)
- 【期望dp】hdu 4405 Aeroplane chess
- Print number in a pyramid pattern
- 二叉排序树
- Aptana插件版Zip包下载方法
- 使用Axis 开发Web Service服务器端
- C#学习之路,学习笔记 第四章 流程控制
- PHP的错误异常信息是否输出
- opencv3.0, vs2013配置
- 给LinearLayout设置点击事件