I'll try solving the general game where objective is to maximise score in t turns.
First thing to notice is each die is independent of every other die. We simply need to solve the strategy for one die, and apply it to each die.
Let f(x,t) denote the expected value we should get if the current number is x, there are t turns left and we play optimally.
f(6,t) = 6 for all t
If there's one turn left we reroll iff x ≤ 3. 3.5 technically
f(1,1) = f(2,1) = f(3,1) = 3.5 (reroll)
f(4,1) = 4, f(5,1) = 5, f(6,1) = 6 (no reroll)
If there's two turns we reroll if reroll gives higher EV.
f(1,2) = max(1, sum f(x,1) / 6 ) = max(1, 4.25) = 4.25
f(2,2) = max(2, 4.25) = 4.25
f(3,2) = max(3, 4.25) = 4.25
f(4,2) = max(4, 4.25) = 4.25
f(5,2) = max(5, 4.25) = 5
f(6,2) = max(6, 4.25) = 6
Now we get our EV for two turns = sum f(x,2) / 6 = 4.666666
f(1,3) = f(2,3) = f(3,3) = f(4,3) = 4.6666666
f(5,3) = 5, f(6,3) = 6
Now for 3 turns, EV = sum f(x,3) / 6 = 4.94444444
f(1,4) = ... f(4,4) = 4.94444444
f(5,4)=5, f(6,4) = 6
Now for 4 turns, EV = 5.12936
Which means reroll for all numbers unless its a 6
Conclusion (assuming my calculations are correct):
If you have 4 or more turns, reroll unless you have a 6
If there's two or three turns left, reroll unless you have 5 or 6
If you have a turn left, reroll unless you have 4, 5 or 6
Apply this independently to each die
The simple formula is to obtain this: f(x,t) = max(x, summation (x varies 1 to m) f(x,t-1) / m) with base case f(x,0) = x. If the
first value is bigger, no reroll is better, if the second is bigger,
reroll is better.
I've solved the strategy explicitly for n 6-sided die, but the formula holds for any m-sided die.