mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 02:03:10 +08:00
build
This commit is contained in:
@ -164,7 +164,7 @@ $$
|
||||
dp[1] = cost[1]
|
||||
dp[2] = cost[2]
|
||||
// 状态转移:从较小子问题逐步求解较大子问题
|
||||
for i in stride(from: 3, through: n, by: 1) {
|
||||
for i in 3 ... n {
|
||||
dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]
|
||||
}
|
||||
return dp[n]
|
||||
@ -421,7 +421,7 @@ $$
|
||||
return cost[n]
|
||||
}
|
||||
var (a, b) = (cost[1], cost[2])
|
||||
for i in stride(from: 3, through: n, by: 1) {
|
||||
for i in 3 ... n {
|
||||
(a, b) = (b, min(a, b) + cost[i])
|
||||
}
|
||||
return b
|
||||
@ -721,7 +721,7 @@ $$
|
||||
dp[2][1] = 0
|
||||
dp[2][2] = 1
|
||||
// 状态转移:从较小子问题逐步求解较大子问题
|
||||
for i in stride(from: 3, through: n, by: 1) {
|
||||
for i in 3 ... n {
|
||||
dp[i][1] = dp[i - 1][2]
|
||||
dp[i][2] = dp[i - 2][1] + dp[i - 2][2]
|
||||
}
|
||||
|
Reference in New Issue
Block a user