Subsets & Combinations - Count of Subsets With Sum K
Suppose the problem changes: now you can use each element in the array unlimited times to form subsets summing to K (i.e., unlimited repetitions allowed). Which modification to the space-optimized DP code below correctly counts the number of such subsets?
def count_subsets_unlimited(arr, K):
dp = [0] * (K + 1)
dp[0] = 1
for num in arr:
for j in range(???):
dp[j] += dp[j - num]
return dp[K]
Choose the correct range for the inner loop to handle unlimited usage of elements.