下面附上Python代码: import numpy as np table = np.zeros([100 + 1, 5 + 1], dtype=int) def spend(n, p):     assert 1 <= p <= n     if n == p:         return 0     minSpend = 10e5     for k in range(1, n - p + 1):         if p == 1:             maxSpend = table[max(k, n - k), 1] + 1         else:             maxSpend = table[n - k, p] + 1             if k < p:                 for i in range(max(1, p + k - n), k + 1):                     currentSpend = table[k, i] + table[n - k, p - i] + 1                     if currentSpend > maxSpend:                         maxSpend = currentSpend             else:                 maxSpend = max(maxSpend, table[k, p])                 for i in range(max(1, p + k - n), p):                     currentSpend = table[k, i] + table[n - k, p - i] + 2                     if currentSpend > maxSpend:                         maxSpend = currentSpend         if maxSpend < minSpend:             minSpend = maxSpend     table[n, p] = minSpend