I don’t know I anyone is still interested in the answer, but there is a problem you might not see in your statement.
When you write of “achieving the following combinations with five dices in two rolls”, you omit the part that you have to chose which dices to keep between the two rolls. While it’s possible to compute for each possible result of the first re-roll which choice of keeping is the best, and say : “suppose we use that strategy”, there are many of them, and could be painful without a bit of programming.
But then, one may note that programming the calculus is the only reasonable way to tackle that kind of calculus ^_^. I could do it, but I’ll not bother to unless somone says he’s still interested in the matter !