Fortune Telling Collection - Free divination - The probability of rolling dice and walking according to the number of steps in the nth grid

The probability of rolling dice and walking according to the number of steps in the nth grid

As the title says:

Like a monopoly, roll the dice and calculate the probability of going to the n-th grid according to the number of dice and steps.

For example, our function dp(n) calculates the probability of the nth grid, and then:

//The number of dice must be (1), which means 1 possibility.

P( 1)= 1 probability of grid = 1/6.

//The number of dice must be (2), (1, 1), two possibilities.

P(2)= probability of the second grid =1/6+(1/6) (1/6).

//Dice number (3), (1, 2), (2, 1), (1, 1)

P(3)= probability of the third grid =1/6+(1/6) (1/6) 2+(1/6) * (1/6).

There are too many permutations and combinations of the fourth one, so I won't continue to list them here.

Let's analyze how this p(n) is calculated. The probability of the nth lattice is actually calculated from the nth-6th lattice to the nth-1lattice.

If n

p( 1)= 1/6

p(2)=p( 1)/6+ 1/6

p(3)= p( 1)/6+p(2)/6+ 1/6

...

If n>6:

p(n)= p(n- 1)/6+p(n-2)/6+p(n-3)/6+p(n-4)/6+p(n-5)/6+p(n-6)/6

Then we just need to calculate the probability from 1

When calculating the probability of 1, the influence of the first lattice on the probability of 2-7 lattices must also be calculated.

p(n+ 1)+=p(n)/6

The specific algorithm is as follows: