hdu4405 Aeroplane chess(期望dp)
来源:互联网 发布:黄金投资 知乎 编辑:程序博客网 时间:2024/05/24 05:41
题意:已知起点(0)和可选步数(1,2…6),每次选择一种走法。且存在一些点之间连通,可以直达。
求第一次大于等于n的期望步数。
解法:简单的期望dp
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>#include<set>#include<vector>#include<map>#define ll long longusing namespace std;const int maxn = 100000+10;int n,m;int vis[maxn];double dp[maxn];int main(){ while(scanf("%d%d",&n,&m)!=EOF){ if(n==0&&m==0) break; memset(dp,0,sizeof(dp)); memset(vis,0,sizeof(vis)); for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); vis[x]=y; } for(int i=n-1;i>=0;i--){ if(vis[i]){ dp[i]=dp[vis[i]]; } else{ double tmp=0.0; for(int k=1;k<=6;k++){ tmp+=dp[i+k]; } dp[i]=tmp/6.0+1.0; } } printf("%.4lf\n",dp[0]); } return 0;}
0 0
- hdu4405 Aeroplane chess(期望dp)
- HDU4405:Aeroplane chess(概率dp & 期望)
- hdu4405 Aeroplane chess 【期望dp】
- 【期望DP】HDU4405 Aeroplane chess
- HDU4405-Aeroplane chess(概率DP求期望)
- hdu4405--Aeroplane chess+概率期望dp
- HDU4405 Aeroplane chess (概率DP求期望)
- hdu4405 Aeroplane chess【概率DP+期望问题】
- hdu4405 Aeroplane chess 期望
- hdu4405[Aeroplane chess] 有点懂了期望概率DP
- hdu4405 Aeroplane chess (概率dp)
- HDU4405--Aeroplane chess--概率DP
- 【HDU4405】【Aeroplane chess】【概率dp】
- hdu4405 Aeroplane chess---金华网络赛 期望
- HDU4405 Areoplane chess(期望dp)
- HDU 4405 Aeroplane chess(期望DP)
- HDOJ 4405 Aeroplane chess(期望DP)
- LightOJ 1030 Discovering Gold + Hdu4405 Aeroplane chess (期望)
- mysql启动错误1067的解决
- 算数运算符与算术表达式
- C++局部类
- AFNetworking-源码解析
- qt设置无窗体圆角窗口
- hdu4405 Aeroplane chess(期望dp)
- FrameWork Learning-Pop
- 利用Handler更简单的实现Service与Activity的通信,更新UI
- 二分图匹配 hdu 1150
- 【C++】关于日历编程的一点思考
- FrameWork Learning-MBProgressHUD
- FrameWork Learning - Mantle
- 递归实现全排列
- Active X不能例示