This is a thinking problem, so alas, you must think about it yourself.
Your professor will probably show the most optimal solution after you turn in your assignment.
When ever I don't know how to program something right away, I think: "How would I do this in real life?" Then I figure out exactly what I did to get the right answer. Then "explain" that to the computer via C++.
I started a solution for this in the morning, as I too thought it was interesting. Then I had to break work, then I came back for 2 hours. I have a solution attempt that repeats several combinations and doesn't necessarily go through all summands. :-S This is harder than usual, or I'm becoming a moron. :-P
you have the mathematical properties of addition and multiplication.
are they commutative? yes
a + b = b + a
a * b = b * a
are they associative? yes
(a + b) + c = a + (b + c)
(a * b) * c = a * (b * c)
are they distributive? partly
a * (b + c) = (a * b) + (a * c)
a + (b * c) != (a + b) * (a + c)
this question is rather about a simplified version of metamorphic coding where you have the simplest version:
50 + 50
and you want to iterate through all the versions until you reach the most complex one:
50 * 2 (in an addition form)
however here the situation is way simper because you dont have nop operators that dont do anything. as opposd to metamorphic code
Modulus should be your friend in finding the answer you seek...
IN other words, if you base number has a remainder of 0 from the current sum, you can make that number divisible by that number, unlocking a possible combination of numbers to equate to 100. Start with you base case, prove and inductive case, and you have the foundation for your algorithm. Obviously the largest case is 50+50, correct?
100%50 = 0
50+50 = 100 // yay! first combination found!
(50%20) = 10 // not a possibility in this iteration
50%10 = 0 // a possible combination
50+10+10+10+10+10 // yay! another combination
50+40+10 // reduced but same result since we are popping a 10 for eval
(10%50) = 10 // nope
(10%20) = 10 // nope
(10%5) = 0 // yay!!!!
50+40+(5+5)
etc... etc.... Almost like Discreet Mathematics!!! I would evaluate it like a quasi tree like form.
because finding the possibility of the division of those additives from 40 needs to be a possibility to acquire one of the sums to 100. such as 50+20+20+10 since 40%20 = 0 so 20*2 = 40. This is because you have to treat that sum as a portion that you should evaluate. You would have to evaluate everything until you get the smallest possible result, which is 5 added 20 times.
My algorithm is similar and still doesn't yield the correct result. I am sorting the summands, meaning I have 5 before 2. But the smallest combination found is 20 * 5 as you say, but it is not the smallest possible one: The smalest is 2 + 2 + 2 ..... 50 times. So it has to be more complex than this.
Also, to avoid duplicates I am thinking I need to hash the combinations and check the collection before adding new ones.