最简单的穷举法,可惜超时了,先留个坑~
class Solution:
# @param {int[][]} costs n x k cost matrix
# @return {int} an integer, the minimum cost to paint all houses
def minCostII(self, costs):
# Write your code here
if len(costs) == 0:
return 0
n = len(costs)
k = len(costs[0])
L = [[0 for i in range(k)] for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(k):
tmp = []
for m in range(k):
if m != j:
tmp.append(costs[i-1][j] + L[i-1][m])
L[i][j] = min(tmp)
return min(L[n])