0-1背包问题
与”0-1背包”的区别: 属性从max改为了个数
时间复杂度
O(N * M)
Python 代码
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [0] * (M + 1)
dp[0] = 1
for i in range(N):
e = A[i]
for j in range(M, e - 1, -1):
dp[j] += dp[j - e]
print(dp[M])