It would seem to me that, for the problem given, greedy is always the best.
However, in general, I would progress from left to right through the list, keeping a complete list of all the possibilities; if there are two or more possibilities that would land you at the same point, prune every possibility that is not the most efficient (depending on the question, you may also prune all but one of identically efficient solutions). Also regularly prune any solution which is a dead end.
So, for your example (I will list each possibility in brackets):
- Move to the first item in your array - 1. You have to start here, so make this your list of possibilities: (1)
- Move to the next item in your array - 3
- For each item in your list of possibilities, copy it, add the item in your array, and then add it to the list of possibilities: (1),(1,3)
- Eliminate any invalid possibilities, or possibilities which can never be valid (none yet)
- For any pair of possibilities which end in the same place, strip all but the most efficient (none yet)
- Move to the next item in your list - 5
- For each item in your list of possibilities, copy it, add the item in your array, and then add it to the list of possibilities: (1),(1,3),(1,5),(1,3,5)
- Eliminate any invalid possibilities, or possibilities which can never be valid (none yet)
- For any pair of possibilities which end in the same place, strip all but the most efficient. (1,5) and (1,3,5) both end on 5, and (1,5) is more efficient, so delete (1,3,5).
- Move to the next item in your list - 10
- For each item in your list of possibilities, copy it, add the item in your array, and then add it to the list of possibilities: (1),(1,3),(1,5),(1,10),(1,3,10),(1,5,10)
- Eliminate any invalid possibilities, or possibilities which can never be valid. (1,10) and (1,3,10) are invalid, and (1) and (1,3) will never be valid (hypothetically, (1,5) could be valid, if this 10 is followed by another 10). This leaves (1,5),(1,5,10)
- For any pair of possibilities which end in the same place, strip all but the most efficient (none found).
- Move to the next item in your list - 15
- For each item in your list of possibilities, copy it, add the item in your array, and then add it to the list of possibilities: (1,5),(1,5,10),(1,5,15),(1,5,10,15),
- Eliminate any invalid possibilities, or possibilities which can never be valid. (1,5,15) is invalid, and (1,5) will never be valid. This leaves (1,5,10),(1,5,10,15)
- For any pair of possibilities which end in the same place, strip all but the most efficient (none found).
- Wash, rinse, repeat.
So the general method is:
- make things a little more complicated
- remove any you can remove