| s | Number of sides on the die. |
| Vₖ | What the game is worth when you still have k re-rolls left and you play perfectly. |
| V₀ = (s+1)/2 | With no re-rolls left you must keep the next roll, so the game is worth the plain EV of one roll. |
| X | The roll you are about to see. |
| Vₖ₋₁ | What you'd be worth if you threw this roll away: the same game with one fewer re-roll. |
| max(X, Vₖ₋₁) | Your payoff after seeing X: keep X, or swap it for the rest of the game. You take whichever is bigger. |
| E[ … ] | Average that payoff over every roll you might see. |
Worked: six-sided die, one re-roll
V₀ = 3.5. On a 1, 2 or 3, re-rolling (worth 3.5) beats keeping, so max = 3.5. On a 4, 5 or 6, keep it. So V₁ = (3.5 + 3.5 + 3.5 + 4 + 5 + 6) ÷ 6 = 25.5 ÷ 6 = 4.25.
With two re-rolls the bar rises to 4.25, so only 5 and 6 are kept: V₂ = (4 × 4.25 + 5 + 6) ÷ 6 = 28 ÷ 6 = 4.67.
Why work backwards? You can't value the first decision without knowing what continuing is worth. Only the last decision has a known continuation (the plain EV), so you start there and move back one step at a time. This method is called backward induction, and it is exactly how American options are priced on a binomial tree: at each node, take the max of exercising now or holding.