hello-algo/codes/rust/chapter_dynamic_programming/climbing_stairs_dfs.rs
sjinzh 459449d41a
zig : upgrade codes && rust : add codes for chapter_searching and chapter_dynamic_programming. (#591)
* zig : update zig codes

* rust : add codes for linear_search and hashing_search

* rust : add codes for linear_search and hashing_search

* rust : add codes for chapter_dynamic_programming
2023-07-10 01:32:12 +08:00

27 lines
No EOL
580 B
Rust

/*
* File: climbing_stairs_dfs.rs
* Created Time: 2023-07-09
* Author: sjinzh (sjinzh@gmail.com)
*/
/* 搜索 */
fn dfs(i: usize) -> i32 {
// 已知 dp[1] 和 dp[2] ,返回之
if i == 1 || i == 2 { return i as i32 };
// dp[i] = dp[i-1] + dp[i-2]
let count = dfs(i - 1) + dfs(i - 2);
count
}
/* 爬楼梯:搜索 */
fn climbing_stairs_dfs(n: usize) -> i32 {
dfs(n)
}
/* Driver Code */
pub fn main() {
let n: usize = 9;
let res = climbing_stairs_dfs(n);
println!("{n} 阶楼梯共有 {res} 种方案");
}