Merge pull request #2457 from tianci-zhang/master

添加0070.爬楼梯完全背包版本.md Python3代码
This commit is contained in:
程序员Carl 2024-03-18 10:00:43 +08:00 committed by GitHub
commit 253bddcf37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 0 deletions

View File

@ -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