From e51ce46b75cae98e8b69bac491151f0a347d10e8 Mon Sep 17 00:00:00 2001 From: zhouzheng Date: Fri, 26 Jan 2024 11:18:54 +0800 Subject: [PATCH] =?UTF-8?q?update:=2070.=20=E7=88=AC=E6=A5=BC=E6=A2=AF?= =?UTF-8?q?=E8=BF=9B=E9=98=B6=E7=89=88=EF=BC=8C=E5=A2=9E=E5=8A=A0=20go=20?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E9=A2=98=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0070.爬楼梯完全背包版本.md | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) 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: