mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
build
This commit is contained in:
@@ -155,8 +155,8 @@ $$
|
||||
// 初始化 dp 表,用于存储子问题的解
|
||||
var dp = Array(repeating: 0, count: n + 1)
|
||||
// 初始状态:预设最小子问题的解
|
||||
dp[1] = 1
|
||||
dp[2] = 2
|
||||
dp[1] = cost[1]
|
||||
dp[2] = cost[2]
|
||||
// 状态转移:从较小子问题逐步求解较大子问题
|
||||
for i in stride(from: 3, through: n, by: 1) {
|
||||
dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]
|
||||
|
||||
Reference in New Issue
Block a user