hdu 4405 Aeroplane chess (概率与期望)
来源:互联网 发布:做视频的软件 编辑:程序博客网 时间:2024/06/17 03:05
题目链接:hdu 4405
dp[i]表示在第i个格子,距离终点状态所需要的期望步数
方程转移:
dp[i]=dp[fa[i]] ->若当前位置可以飞行
dp[i]+=(dp[i+j]+1)/6 (1<=j<=6)
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn (1000000+10)int N,M;int fa[maxn];double dp[maxn];inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}int main(){while(scanf("%d%d",&N,&M)==2){if(N==0&&M==0)break;memset(fa,0,sizeof(fa));memset(dp,0,sizeof(dp));for(int i=1;i<=M;i++){int x=read(),y=read();fa[x]=y;}for(int i=N-1;i>=0;i--){if(fa[i]){dp[i]=dp[fa[i]];}else {for(int j=1;j<=6;j++)dp[i]+=(dp[i+j]+1.0)/6.0;}}printf("%.4lf\n",dp[0]);}return 0;}
0 0
- hdu 4405 Aeroplane chess (概率与期望)
- 概率与期望 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)
- 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 (简单期望)
- HDU 4405 Aeroplane chess 概率dp求期望
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- hdu 4405 Aeroplane chess【概率DP求期望】
- Aeroplane chess 4405 hdu 概率DP求期望入门题
- CUDA 两个向量相加: 当数组的元素个数大于所开的线程数量的时候的解决办法
- javascript正则表达式,源代码为dorado框架的
- Java中常用设计模式总结
- UITableView编辑模式可以点击Cell
- 递归算法求幂
- hdu 4405 Aeroplane chess (概率与期望)
- 如何读写uboot的参数区参数
- 模版方法模式
- C语言总结——关键字和预处理
- visual studio 环境语言设置
- 离线安装Cloudera Manager 5和CDH5(最新版5.1.3) 完全教程
- css定位
- vs2008, qt生成库文件 以及qt应用程序调用库文件方法
- js中(function(){…})()立即执行函数写法理解