From f926ac8f390f63236426ca29f2bfd63ad98685c9 Mon Sep 17 00:00:00 2001 From: Tiana <51739436+tianci-zhang@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:45:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00070.=E7=88=AC=E6=A5=BC?= =?UTF-8?q?=E6=A2=AF=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC?= =?UTF-8?q?.md=20Python3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加0070.爬楼梯完全背包版本.md Python3代码 --- problems/0070.爬楼梯完全背包版本.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md index 4fa294cf..622b1117 100644 --- a/problems/0070.爬楼梯完全背包版本.md +++ b/problems/0070.爬楼梯完全背包版本.md @@ -165,7 +165,21 @@ class climbStairs{ ``` ### Python3: +```python3 +def climbing_stairs(n,m): + dp = [0]*(n+1) # 背包总容量 + dp[0] = 1 + # 排列题,注意循环顺序,背包在外物品在内 + for j in range(1,n+1): + for i in range(1,m+1): + if j>=i: + dp[j] += dp[j-i] # 这里i就是重量而非index + return dp[n] +if __name__ == '__main__': + n,m = list(map(int,input().split(' '))) + print(climbing_stairs(n,m)) +``` ### Go: