mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-24 17:17:14 +00:00
rust and zig : add codes for chapter_dynamic_programming (#606)
* rust : add codes for chapter_dynamic_programming * zig : add codes for chapter_dynamic_programming * rust : add codes for chapter_backtracking * Update n_queens.rs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
/* 记忆化搜索 */
|
||||
fn dfs(i: usize, mem: &mut [i32]) -> i32 {
|
||||
// 已知 dp[1] 和 dp[2] ,返回之
|
||||
if i == 1 || i == 2 { return i as i32};
|
||||
if i == 1 || i == 2 { return i as i32; }
|
||||
// 若存在记录 dp[i] ,则直接返回之
|
||||
if mem[i] != -1 { return mem[i] };
|
||||
if mem[i] != -1 { return mem[i]; }
|
||||
// dp[i] = dp[i-1] + dp[i-2]
|
||||
let count = dfs(i - 1, mem) + dfs(i - 2, mem);
|
||||
// 记录 dp[i]
|
||||
|
||||
Reference in New Issue
Block a user