def _change_memo(amount, coins, T, n):
    """Helper function for num_coin_changes_memo()."""
    # Base cases.
    if amount < 0:
        return 0
    if amount == 0:
        return 1

    if n <= 0 and amount > 0:
        return 0

    # Apply memoization.
    if T[n][amount]:
        return T[n][amount]

    # Sum num of ways with coin n included & excluded.
    T[n][amount] = (_change_memo(amount - coins[n - 1], coins, T, n)
                    + _change_memo(amount, coins, T, n - 1))

    return T[n][amount]