题目
Rimi learned a new thing about integers, which is - any positive integer greater than 1 can be divided by its divisors. So, he is now playing with this property. He selects a number N. And he calls this D.
In each turn he randomly chooses a divisor of D (1 to D). Then he divides D by the number to obtain new D. He repeats this procedure until Dbecomes 1. What is the expected number of moves required for N to become 1.
大概就是说一个数每次除以他的因子,问这个数变为1的步数期望
题解
期望倒着推,概率正着推
很有趣的一道题,和杭电上的飞行棋那题有点像.
很显然:ex[1]=0
然后我们考虑2: 2可以到达1,2,那么ex[2]=$\frac{1}{2} $ex[1]+$\frac{1}{2}$ex[2]+1.
因为2可以到达1或者2概率都为1/2,然后再加上这次所花费的步数1.
同理 ex[6]=$\frac{1}{4}$ex[1]+$\frac{1}{4}$ex[2]+$\frac{1}{4}$ex[3]+$\frac{1}{4}$ex[6]+1.
代码
1 | //感觉这种记忆化写法挺常见的,以前在区域赛写过一次, |