hdu4405Aeroplane chess 概率dp水题

//从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 ;

}

时间: 2024-11-08 17:08:20

hdu4405Aeroplane chess 概率dp水题的相关文章

HDU 4405 Aeroplane chess 概率DP 水题

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2327    Accepted Submission(s): 1512 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids lab

Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃圾,大哥拿来了一袋老鼠,其中有w只白老鼠和b只黑老鼠.胡小兔先抓,先抓到白老鼠的人赢. 每次学姐抓完老鼠之后,总会有另外一只老鼠从袋子里自己跑出来(这只老鼠不算任何人抓的),而胡小兔抓老鼠时则不会发生这样的事. 每次袋子里的每只老鼠被抓到的概率相等,当有一只老鼠跑出来的时候,每只老鼠跑出来的几率也相

13年山东省赛 The number of steps(概率dp水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Memory Limit: 128 M Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two ro

LightOJ1030 Discovering Gold 概率DP 水题

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1.

hdu3722Card Game 概率dp水题

//3中天气前一天天气为i转为第二天天气为j的概率为p[i][j] //问第一天天气为i,n天后天气为j的概率 //dp[i][j][k]在第一天天气为j的情况下第n天的天气为j的概率 //dp[i][j][k] += dp[i-1][j][s]*dp[1][s][k] ; #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 1010 ;

hdu 4405 Aeroplane chess 概率dp入门题

Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3

poj 3071 Football (概率DP水题)

G - Football Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams

HDU 4576 Robot 概率DP 水题

Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 3851    Accepted Submission(s): 1246 Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells.

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t