It's one of the most beautiful dp I ever used. I'm going to explain it with an example.
Problem: 1265E
Solution: suppose ei equals the expected number of days that we stop if starting of i-th mirror.
ei=pi∗ei+1+(1−pi)∗e1+1
en=(1−pi)∗e1+1
So how to update e?! :D
We will change how we show numbers. You know how we show complex numbers (if you don't learn it here), we are going to use the same idea.
Each number consists a part that is e1 and another part that is a Real number(in this problem you can change it to integer when using modulo).
We show each number with x and y such that the number is equal to x∗e1+y. So we use this idea and start updating e backward.
Then we will get e1=x∗e1+y and now we can get e1 as an intiger.
e1=y/(1−x)
Any other problem that uses the same idea, please mention. :D