当前位置:网站首页>Leetcode: Sword finger offer II 091 Painting house [2D DP]
Leetcode: Sword finger offer II 091 Painting house [2D DP]
2022-06-25 13:20:00 【Review of the white speed Dragon King】

analysis
dp [i][j] It means the first one i A house is painted j Minimum cost of colors
dp[i][j] = min(dp[i - 1][jother]) + costs[i][j]
ac code
class Solution:
def minCost(self, costs: List[List[int]]) -> int:
n = len(costs)
dp = [[0] * 3 for _ in range(n)]
# init
for j in range(3):
dp[0][j] = costs[0][j]
for i in range(1, n):
dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + costs[i][0]
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + costs[i][1]
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) + costs[i][2]
return min(dp[-1])
summary
Simple dp
边栏推荐
- Restful and RPC
- Germany holds global food security Solidarity Conference
- JVM parameter interpretation
- 关于猜数字游戏的实现
- [flask tutorial] flask development foundation and introduction
- Drago Education - typescript learning
- 15 basic SEO skills to improve ranking
- JVM参数解释
- KDD 2022 | GraphMAE:自监督掩码图自编码器
- [pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
猜你喜欢
随机推荐
C# 切换中英文输入法
Capabilities required by architects
Sword finger offer II 028 Flatten multi-level bidirectional linked list
Where is it safe to open an account for buying funds? Please give me your advice
[pit avoidance means "difficult"] antd select fuzzy search
坡道带来的困惑
How unity makes the UI intercept click events
关于数据在内存中存储的相关例题
关于一道教材题的讲解
.NET in China - What's New in .NET
Of binary tree_ Huffman tree_ Huffman encoding
Seven competencies required by architects
About data storage in memory
Stockage des données en mémoire
Jenkins pipeline uses
几分钟上线一个网站 真是神器
爱可可AI前沿推介(6.25)
Nova中的api
汇编标志位相关知识点(连)
剑指 Offer II 025. 链表中的两数相加








