One person Game Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=4405
Test instructions
There was a man playing flying chess, the rule is: Throw a dice, you can fly from the current point X (x+ points), there are some flight channels on the board, if the point x and Point y there is a flight path, then when you go to the X, you will fly to the point Y, starting at 0, to fly from the beginning to the end of the n need to throw the number of
Exercises
A simple question to ask for, not to expect.
When the point I is the starting point of the flight path, because do not need to throw the dice, you can fly to the end of the flight path, so this time dp[i]=dp[the end of the flight path]
When the point I is not the beginning of the flight path, the dice can fly to i+ points at the time, so at this time DP[I]=∑DP[I+K]*1/6 +1
Code
#include <stdio.h>
#include <string.h>
using namespace Std;
const int n=100005;
Double Dp[n];
int q[n];
int main ()
{
int n,m,x,y;
while (~SCANF ("%d%d", &n,&m) && (n| | m))
{
memset (q,0,sizeof (q));
Memset (Dp,0,sizeof (DP));
while (m--)
{
scanf ("%d%d", &x,&y);
Q[x]=y;
}
for (int i=n-1;i>=0;--i)
if (!q[i])
{
for (int j=1;j<=6;++j)
if (i+j<=n) dp[i]+=dp[i+j]/6.0;
dp[i]++;
}
else Dp[i]=dp[q[i]];
printf ("%.4f\n", dp[0]);
}
}
HDU 4405:aeroplane Chess probability DP seeking expectation