diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md index f8337cc0..4fa294cf 100644 --- a/problems/0070.爬楼梯完全背包版本.md +++ b/problems/0070.爬楼梯完全背包版本.md @@ -169,7 +169,32 @@ class climbStairs{ ### Go: +```go +func climbStairs(n int, m int) int { + dp := make([]int, n+1) + dp[0] = 1 + for i := 1; i <= n; i++ { + for j := 1; j <= m; j++ { + if i-j >= 0 { + dp[i] += dp[i-j] + } + } + } + return dp[n] +} +func main() { + // 读取输入n,m + reader := bufio.NewReader(os.Stdin) + input, _ := reader.ReadString('\n') + input = strings.TrimSpace(input) + nv := strings.Split(input, " ") + n, _ := strconv.Atoi(nv[0]) + m, _ := strconv.Atoi(nv[1]) + result := climbStairs(n, m) + fmt.Println(result) +} +``` ### JavaScript: