Title Link: http://acm.acmcoder.com/showproblem.php?pid=4405
Test instructions: Chess pieces, from 0 to N, put the dice, set to a few steps forward, there will be shortcuts, such as 2 and 5 connected together, then you go to 2 o'clock can jump to 5, if 5 and 8 connected together, then you can continue to jump to 8, and finally asked to jump to n when the average number of dice. That is to ask for hope.
Solution: Common probability dp,dp[n] = = 0; forward recursion.
Code:
#include <stdio.h>#include <string.h>#include <vector>#include <string>#include <algorithm>#include <iostream>#include <iterator>#include <fstream>#include <set>#include <map>#include <math.h>using namespace STD;Const intMAXN =100010;intP[MAXN];intM, n, x, y;intEX[MAXN];DoubleDP[MAXN];intMain () { while(Cin>> n >> m) {if(n = =0&& m = =0) Break;memset(DP,0,sizeof(DP));memset(ex,-1,sizeof(ex)); for(inti =1; I <= m; i++) {Cin>> x >> y; Ex[x] = y; } for(inti = n-1; I >=0; i--) {if(Ex[i]! =-1) Dp[i] = dp[ex[i]];Else{ for(intj =1; J <=6; J + +) {if(i + j >= N) dp[i] + = (1.0/6) * Dp[n];ElseDp[i] + = (1.0/6) * dp[i + j]; } Dp[i] + =1; } }printf("%.4lf\n", dp[0]); }return 0;}
HDU 4405 Aeroplane Chess "probability DP seeking expectation"