mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	* feat(go/dp): support climbing stairs * feat(go/dp): support knapsack * feat(go/dp): coin_change & edit_distance
		
			
				
	
	
		
			22 lines
		
	
	
		
			402 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			402 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// File: climbing_stairs_dfs.go
 | 
						|
// Created Time: 2023-07-18
 | 
						|
// Author: Reanon (793584285@qq.com)
 | 
						|
 | 
						|
package chapter_dynamic_programming
 | 
						|
 | 
						|
/* 搜索 */
 | 
						|
func dfs(i int) int {
 | 
						|
	// 已知 dp[1] 和 dp[2] ,返回之
 | 
						|
	if i == 1 || i == 2 {
 | 
						|
		return i
 | 
						|
	}
 | 
						|
	// dp[i] = dp[i-1] + dp[i-2]
 | 
						|
	count := dfs(i-1) + dfs(i-2)
 | 
						|
	return count
 | 
						|
}
 | 
						|
 | 
						|
/* 爬楼梯:搜索 */
 | 
						|
func climbingStairsDFS(n int) int {
 | 
						|
	return dfs(n)
 | 
						|
}
 |