hdu4405Aeroplane chess 概率dp水题
来源:互联网 发布:linux文件列表 编辑:程序博客网 时间:2024/06/07 19:29
//从0到n有n+1个格子
//对于格子i,掷一次骰子的数为x,那么可以从位置i到位置i+x
//格子之间有连线,如果格子a和b有连线,那么从a到b不用掷骰子
//求从0到n的骰子掷的次数的期望
//dp[i] = 1/6*segma(dp[k]) + 1 (i<=k<=i+6)
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std ;
const int maxn = 100000 ;
double dp[maxn] ;
int line[maxn] ;
int main()
{
int n , m ;
while(scanf("%d%d" , &n ,&m) && n+m)
{
memset(line , -1 , sizeof(line)) ;
memset(dp , 0 ,sizeof(dp)) ;
int a , b ;
for(int i = 1;i <= m ;i++)
{
scanf("%d%d" ,&a , &b) ;
line[a] = b ;
}
for(int i = n-1 ;i >= 0 ;i--)
{
if(line[i] != -1){dp[i] = dp[line[i]] ;continue;}
for(int k = i + 1;k <= i+6 ;k++)
dp[i] += ((double)1/(double)6)*dp[k];
dp[i] += 1 ;
}
printf("%.4lf\n" , dp[0]) ;
}
return 0 ;
}
//对于格子i,掷一次骰子的数为x,那么可以从位置i到位置i+x
//格子之间有连线,如果格子a和b有连线,那么从a到b不用掷骰子
//求从0到n的骰子掷的次数的期望
//dp[i] = 1/6*segma(dp[k]) + 1 (i<=k<=i+6)
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std ;
const int maxn = 100000 ;
double dp[maxn] ;
int line[maxn] ;
int main()
{
int n , m ;
while(scanf("%d%d" , &n ,&m) && n+m)
{
memset(line , -1 , sizeof(line)) ;
memset(dp , 0 ,sizeof(dp)) ;
int a , b ;
for(int i = 1;i <= m ;i++)
{
scanf("%d%d" ,&a , &b) ;
line[a] = b ;
}
for(int i = n-1 ;i >= 0 ;i--)
{
if(line[i] != -1){dp[i] = dp[line[i]] ;continue;}
for(int k = i + 1;k <= i+6 ;k++)
dp[i] += ((double)1/(double)6)*dp[k];
dp[i] += 1 ;
}
printf("%.4lf\n" , dp[0]) ;
}
return 0 ;
}
0 0
- hdu4405Aeroplane chess 概率dp水题
- hdu4405Aeroplane chess【概率DP】
- hdu4405 Aeroplane chess (概率dp)
- HDU4405--Aeroplane chess--概率DP
- 【HDU4405】【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
- Qt学习之一,键盘事件细节
- glActiveTexture
- OC中的数组
- HDU4344 Mark the Rope pollard_rho大整数分解应用
- JavaScript权威指南_131_第15章_脚本化文档_15.6-创建、 插入、删除节点-DocumentFragment
- hdu4405Aeroplane chess 概率dp水题
- HDU1005 Number Sequence
- web技术发展史
- S3C2410的触摸屏控制
- OC多态使用注意
- UVa 10189 SDNU 1127 Minesweeper 【7月20】
- HDU 5285:wyh2000 and pupil
- 2015年ALPC暑期专题练习I (计算几何) Space Ant
- 知识储备:JSON数据解析