hi Lewis,
I was still thinking about what Winston and Carey wrote in your other topic.
But this one: I think it is O(2^n), can't improve on that.
Think of generating all possible subsets of a set of N. Including the
empty set, there are 2^N of 'm. Each having its own sum.
So, you can also try to write a recursive routine that determines
all subsets, and map each of these to its sum. That will give you an excellent
way to
test you present method.
I wrote one myself some time ago. The problem was the classic
water pouring
problem. Given N glasses of certain volumes, can you generate a certain
volume by filling, emptying and pouring the avalilable glasses?
I wanted to solve the problem that a certain combination of the glasses,
when summing their volumes, would give the required volume.
I did that by indeed creating all subsets and see if any sum would equal
the target.
Maybe a nice idea for the next puzzle?