def _top_down_cut_rod_recursive(n: int, prices: list, max_rev: list):
    '\n    Constructs a top-down dynamic programming solution for the rod-cutting problem\n    via memoization.\n\n    Runtime: O(n^2)\n\n    Arguments\n    --------\n    n: int, the length of the rod\n    prices: list, the prices for each piece of rod. ``p[i-i]`` is the\n    price for a rod of length ``i``\n    max_rev: list, the computed maximum revenue for a piece of rod.\n    ``max_rev[i]`` is the maximum revenue obtainable for a rod of length ``i``\n\n    Returns\n    -------\n    The maximum revenue obtainable for a rod of length n given the list of prices\n    for each piece.\n    '
    if (max_rev[n] >= 0):
        return max_rev[n]
    elif (n == 0):
        return 0
    else:
        max_revenue = float('-inf')
        for i in range(1, (n + 1)):
            max_revenue = max(max_revenue, (prices[(i - 1)] + _top_down_cut_rod_recursive((n - i), prices, max_rev)))
        max_rev[n] = max_revenue
    return max_rev[n]
Constructs a top-down dynamic programming solution for the rod-cutting problem
via memoization.

Runtime: O(n^2)

Arguments
--------
n: int, the length of the rod
prices: list, the prices for each piece of rod. ``p[i-i]`` is the
price for a rod of length ``i``
max_rev: list, the computed maximum revenue for a piece of rod.
``max_rev[i]`` is the maximum revenue obtainable for a rod of length ``i``

Returns
-------
The maximum revenue obtainable for a rod of length n given the list of prices
for each piece.
def _top_down_cut_rod_recursive(n: int, prices: list, max_rev: list):
    '\n    Constructs a top-down dynamic programming solution for the rod-cutting problem\n    via memoization.\n\n    Runtime: O(n^2)\n\n    Arguments\n    --------\n    n: int, the length of the rod\n    prices: list, the prices for each piece of rod. ``p[i-i]`` is the\n    price for a rod of length ``i``\n    max_rev: list, the computed maximum revenue for a piece of rod.\n    ``max_rev[i]`` is the maximum revenue obtainable for a rod of length ``i``\n\n    Returns\n    -------\n    The maximum revenue obtainable for a rod of length n given the list of prices\n    for each piece.\n    '
    if (max_rev[n] >= 0):
        return max_rev[n]
    elif (n == 0):
        return 0
    else:
        max_revenue = float('-inf')
        for i in range(1, (n + 1)):
            max_revenue = max(max_revenue, (prices[(i - 1)] + _top_down_cut_rod_recursive((n - i), prices, max_rev)))
        max_rev[n] = max_revenue
    return max_rev[n]