You are given a m x n matrix representing m houses and n colors, each index (i,j) represents pointing house i and with color j for 0 <= i < m and 0 <= j < n. Given that no adjacent houses can have the same color, write an algorithm that computes the minimum cost of pointing all m houses while following the given constraint.
Answer:
def findMinimum(matrix):
#Your code hereI wrote a code that had a m * n^m run time. I don't think dp would work in this scenario since the constraint keeps changing, can anyone tell me what the fastest algorithm would be?