您的位置:首页 > 大数据 > 人工智能

LintCode: Paint House II

2016-04-25 23:50 501 查看
LintCode: Paint House II

最简单的穷举法,可惜超时了,先留个坑~

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
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: