mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-16 03:59:18 +08:00
Fix a definition.
This commit is contained in:
@@ -63,7 +63,7 @@ fn knapsack_dp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {
|
||||
dp[n][cap]
|
||||
}
|
||||
|
||||
/* 0-1 背包:状态压缩后的动态规划 */
|
||||
/* 0-1 背包:空间优化后的动态规划 */
|
||||
fn knapsack_dp_comp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {
|
||||
let n = wgt.len();
|
||||
// 初始化 dp 表
|
||||
@@ -104,7 +104,7 @@ pub fn main() {
|
||||
let res = knapsack_dp(&wgt, &val, cap);
|
||||
println!("不超过背包容量的最大物品价值为 {res}");
|
||||
|
||||
// 状态压缩后的动态规划
|
||||
// 空间优化后的动态规划
|
||||
let res = knapsack_dp_comp(&wgt, &val, cap);
|
||||
println!("不超过背包容量的最大物品价值为 {res}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user