Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6debcdd

Browse files
committed
Create Pack-ProblemVariants.py
1 parent 97f6a41 commit 6debcdd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
# 完全问题求解方案总数
3+
def zeroOnePackNumbers(self, weight: [int], value: [int], W: int):
4+
size = len(weight)
5+
dp = [0 for _ in range(W + 1)]
6+
7+
# 枚举前 i 种物品
8+
for i in range(1, size + 1):
9+
# 正序枚举背包装载重量
10+
for w in range(weight[i - 1], W + 1):
11+
dp[w] = sum(dp[w], dp[w - weight[i - 1]])
12+
13+
return dp[W]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /