Definition · An allocation problem, and its stateGiven activities 1 to n, a whole number u of indivisible units to hand out, and a return table giving rᵢ(x) for each activity i and each whole x from 0 up, choose x₁, ..., xₙ with Σ xᵢ ≤ u maximising Σ rᵢ(xᵢ).
The state before activity i decides is the number of units still unspent. The value function is g(i, s) = max over x from 0 to s of rᵢ(x) + g(i+1, s−x), with g(n+1, s) = 0 for every s: once there are no activities left, what remains is worth nothing.
Two things about that definition are worth saying out loud. The first is that rᵢ(0) must be 0 — a table whose first column is not zero is measuring something other than a return, and the lab refuses it by name. The second is that nothing anywhere records which activity took what; the state is a single number. That is not an economy, it is the modelling claim, and it is the thing to check before trusting any answer the table produces.
the table units: 0 1 2 3 4
P 0 2 4 15 16
Q 0 6 8 9 10
R 0 3 7 8 9
the network it forces, with four units to hand out:
stage P stage Q stage R done
4 left --2u-> 2 left --1u-> 1 left --1u-> 0 left
3 left 1 left 0 left
2 left 0 left
1 left
0 left
an arc from s left to s-x left carries the return of x units
5 nodes per stage, 4 stages: 20 state values in all
Filled from the finish back, the last column is zero everywhere, R's column is just its own returns, Q's column combines its returns with R's, and P's column combines all three. The value at the node marked 4 left in P’s column is 21, attained by P taking 3, Q taking 1 and R taking none. The lab prices all 35 ways of splitting four units across three activities and finds 21 as well, attained by exactly that split and no other.
The rule that looks at the next unit
Hand out the units one at a time. The first unit goes to Q, which gains 6 against P's 2 and R's 3. The second goes to R at 3, since Q's next unit gains only 2 and P's still gains 2. The third goes to R again at 4. The fourth is a tie among gains of 2, and whichever way it falls the total is 15. Every one of those comparisons is correct and the answer is six short.
Example · Why it loses, in one lineP's returns are 0, 2, 4, 15, 16, so its first two units gain 2 each and its third gains 11. A rule that asks only what the next unit is worth never sees the 11, because it never gets past the two units of 2 that stand in front of it.
The recursion sees it because it never asks about a unit at all: it asks what P should take given how much is left, and 3 is one of the options it prices. That is the difference between choosing a decision and choosing an increment, and the table's jump is there to make it visible rather than arguable.
Diminishing returns, and the tie that appears
Switch to the example whose three activities all have non-increasing marginal returns and the shortcut stops losing: the greedy split and the recursion both reach 19. But look at what the enumeration says about that 19. There are two splits attaining it — one unit to P, two to Q, one to R, and two to P, one to Q, one to R — so even in the friendly case the answer is a set, and a page printing one of them would be printing a choice the model never made.
That is the same point as the ties on the previous page, arriving from a different direction, and it is why the lab prints both the route the recursion reconstructed and every split the enumeration found. Where the two examples differ is in what the tie costs you. A tie among optimal routes is a free choice; the shortcut's failure is not a tie at all, it is a worse answer that looks like a method.
What the state left out
The model here says that four units handed to P, Q and R in any order are worth the sum of three table lookups. That rules out a great deal: no activity can make another cheaper, no unit can be split, no combination can be forbidden, and nothing costs anything to set up. Each of those, if true of the situation, is a state the model does not carry — and the recursion would still return an exact optimum, of the problem it was given.
Two activities rather than three is worth a minute, because the whole table fits on one line: with P at 0, 7, 11, 14, 15 and Q at 0, 5, 10, 13, 16, four units split two and two return 21, out of 15 possible splits. Small enough to check every one of them by hand, which is the only way to be sure the recursion is not being believed rather than checked.