Possible Duplicate:
Sum-subset with a fixed subset size
So I have an array A
, with elements A[1], A[2] .. A[N]
I want to find a subsequence (not necessarily contiguous), with exactly K
elements, whose sum is exactly Sum
.
My best guess is of O(NK), if you run K nested loops, and test every possibility.
Can this be done faster?
All elements of A
are integers, greater than 0.