Prepare 1.1.0 release (#1274)

* Update bucket_sort.c

* Fix the comments in quick_sort.c

* Update the announce badge

* Sync zh and zh-hant versions

* Update contributors list.

* Sync zh and zh-hant versions.

* Sync zh and zh-hant versions.

* Update the contributors list

* Update the version number
This commit is contained in:
Yudong Jin
2024-04-14 20:46:20 +08:00
committed by GitHub
parent 16942dfe32
commit d484b08c15
43 changed files with 471 additions and 115 deletions

View File

@ -27,7 +27,9 @@ fun climbingStairsDPComp(n: Int): Int {
var a = 1
var b = 2
for (i in 3..n) {
b += a.also { a = b }
val temp = b
b += a
a = temp
}
return b
}

View File

@ -59,11 +59,7 @@ fun knapsackDFSMem(
}
/* 0-1 背包:動態規劃 */
fun knapsackDP(
wgt: IntArray,
_val: IntArray,
cap: Int
): Int {
fun knapsackDP(wgt: IntArray, _val: IntArray, cap: Int): Int {
val n = wgt.size
// 初始化 dp 表
val dp = Array(n + 1) { IntArray(cap + 1) }
@ -83,11 +79,7 @@ fun knapsackDP(
}
/* 0-1 背包:空間最佳化後的動態規劃 */
fun knapsackDPComp(
wgt: IntArray,
_val: IntArray,
cap: Int
): Int {
fun knapsackDPComp(wgt: IntArray, _val: IntArray, cap: Int): Int {
val n = wgt.size
// 初始化 dp 表
val dp = IntArray(cap + 1)
@ -97,8 +89,7 @@ fun knapsackDPComp(
for (c in cap downTo 1) {
if (wgt[i - 1] <= c) {
// 不選和選物品 i 這兩種方案的較大值
dp[c] =
max(dp[c], dp[c - wgt[i - 1]] + _val[i - 1])
dp[c] = max(dp[c], dp[c - wgt[i - 1]] + _val[i - 1])
}
}
}