今際の国の呵呵君
Wednesday, November 8, 2017
[LeetCode]Paint House
用DP[i][k]代表第i个房子用第k个颜色paint情况下,总的cost最小的值。那么我们有递推公式:
DP[i][k] = cost[i][k] + min(DP[i - 1][j]), where j != k
那么对于这道题,k = 3。并且我们可以用滚动数组把空间优化到常数,时间复杂度O(n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment