from typing import List


def dynamic_approach(costs: List[List[int]]) -> int:
    """
    The dynamic approach.
    We arrange a table of size houses by colours, and pick the minimum accumulating cost at each round.
    :param costs: the costs per house by colour.
    :return: the minimum cost
    """
    num_houses = len(costs)
    num_colours = len(costs[0])

    cost_table = [[0] * num_colours for _ in range(num_houses)]

    # Initialize the first row.
    for c in range(num_colours):
        cost_table[0][c] = costs[0][c]

    # Dynamically proceed.
    for h in range(1, num_houses):
        for c in range(num_colours):
            cost_table[h][c] = min([cost_table[h-1][cp] + costs[h][c] for cp in range(num_colours) if cp != c])

    for i in cost_table:
        print(i)
    return min(cost_table[num_houses-1])