Subset sum dynamic programming
ID: subset-sum-dynamic-programming
For indexed occurrences with positive integer weights, let record whether a subset of the first entries has sum . The recurrence chooses whether the last occurrence is absent or present: , with an out-of-range term false. Initialize only sum zero true. Descending one-dimensional updates prevent reusing the current occurrence. Time is for target and space ; positivity permits immediate rejection above the total. With weights bounded by , the total is at most , making the bound polynomial in .
New to topics? Read the docs here!