For small values of n, the optimal r can also be obtained by standard dynamic programming methods.
对于较小的 n 值， 最优的 r 也可以通过动态规划方法得到。