Dynamic Programming: Knapsack - Equal Partition (Partition Equal Subset Sum)
Consider the following Python code for the Equal Partition problem. What is the value of dp[target] after processing the input
[1, 5, 11, 5]?
def canPartition(nums):
total = sum(nums)
if total % 2 != 0:
return False
target = total // 2
dp = [False] * (target + 1)
dp[0] = True
for num in nums:
for w in range(target, num - 1, -1):
dp[w] = dp[w] or dp[w - num]
return dp[target]
print(canPartition([1,5,11,5]))
