def solve_iter(n, memo):
    """
    Dynamic programming in a down-top way.
    The function can be enhanced by only store three elements, which can save sapce usage.
    """
    if n == 1 or n == 2 or n == 3:
        return memo[n]
    else:
        for i in range(4, n+1):
            memo[i] = memo[i-1] + memo[i-2] + memo[i-3]
    return memo[n]