class Solution:
# @param {int[][]} costs n x 3 cost matrix
# @return {int} an integer, the minimum cost to paint all houses
def minCost(self, costs):
# Write your code here
L = [[0 for i in range(3)] for i in range(len(costs) + 1)]
for i in range(1, len(costs) + 1):
for j in range(3):
if j == 0:
L[i][j] = min(costs[i-1][0] + L[i-1][1], costs[i-1][0] + L[i-1][2])
if j == 1:
L[i][j] = min(costs[i-1][1] + L[i-1][0], costs[i-1][1] + L[i-1][2])
if j == 2:
L[i][j] = min(costs[i-1][2] + L[i-1][0], costs[i-1][2] + L[i-1][1])
return min(L[len(costs)])
LintCode:Paint House
最新推荐文章于 2020-04-25 14:04:44 发布