Write a function named subsetSums
that uses dynamic programming to find the number of sub-lists of a vector that have a given sum.
Your function accepts a reference to a vector
of integers and a target value k as parameters and returns the number of sub-lists that sum to exactly k.
For example, if the vector stores {9, 4, 20, 10, 3, 5}
and k is 33
, the sub-lists of {9, 4, 20}
and {20, 3, 10}
add to that sum, so you should return 2
.
The key constraint of this problem is that you must solve it using a bottom-up dynamic programming approach.
Do not use recursion. Your solution must use dynamic programming instead.
You are allowed to construct any data structures (array, vector, set, map, etc.) necessary to store the data for your dynamic programming algorithm.
Note: It is possible to solve this problem in O(N) time where N is the number of elements in the vector.