PLAIN/TEXT — ISSUE 219/456 COMPUTER SCIENCE · FOUNDATION / DYNAMIC PROGRAMMING · ~4 MIN READING DATE: 2027-05-08 ARCHIVE: https://plaintext.click/newsletter/ SUBJECT: How a table can replace a forest of repeated choices How a table can replace a forest of repeated choices ==================================================== / START HERE A game board may offer a small reward on each square you cross. Dynamic programming is a way of solving a problem by storing answers to smaller overlapping problems and combining them. Instead of recalculating every possible journey from scratch, the program remembers the best result for each situation that matters. / WHY NOW Suppose you may move only right or down through a reward grid. Many possible routes share the same final stretch or reach the same square. A useful stored answer lets those routes reuse work without assuming that the locally biggest reward is always the best next move. / THE IDEA Define a smaller problem precisely: what is the greatest reward obtainable upon reaching this square? Any route reaching an interior square must arrive from the square immediately above or immediately left. Compare the best rewards already known for those two predecessors, then add the current reward. The move restriction makes an evaluation order possible. Fill the top row and left column first, then work across successive rows. Each answer depends only on answers already available. A table entry summarises all earlier route choices; it need not store every route separately. / THE FORMAL IDEA B(r,c) = v(r,c) + max(B(r−1,c), B(r,c−1)) - B(r,c) = best total at row r, column c; v(r,c) = reward on that square. - max selects the larger predecessor total. Start with the top-left reward; on the top row or left edge there is only one permitted predecessor. / RUN THE TINY EXAMPLE Change one thing. Predict what happens. Rewards are top row [1, 2], bottom row [4, 1]. The best totals are top row [1, 3], bottom row [5, 6]. The final choice compares 3 from above with 5 from the left, then adds 1. Change the top-right reward from 2 to 8: totals become [1, 9] and [5, 10]. The best journey changes from down-then-right to right-then-down. The procedure does not cling to a previous route; it recomputes the affected summary and lets that change propagate to the final answer. / SO WHAT? This is more than caching arbitrary calculations. The smaller answers must contain everything needed for later decisions. If collecting a special key changes which later doors can open, position alone is no longer enough: the stored situation must also record whether the key has been collected. / ONE CAVEAT This example has no revisiting and an additive reward. Cycles, limits on repeated rewards or hidden dependencies require a different state definition. Storing too little gives wrong answers; storing too much can make the table prohibitively large. / KEEP THIS Reuse smaller answers only after defining a state that preserves every past detail capable of changing future choices. / SOURCE TRAIL [1] MIT — Dynamic programming foundations https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/resources/mit6_006s20_lec15/ NEXT: Why mixing coloured lights differs from mixing filters --- HARD IDEAS. PLAIN TEXT. You are receiving this because you asked for one clear computer-science or physics idea each day. Unsubscribe: https://plaintext.click/unsubscribe View in browser: https://plaintext.click/newsletter/2027/05/2027-05-08-dynamic-programming-grid.html From: Plain/Text / Brickston Consulting · 30 N Gould St Ste N, Sheridan, WY 82801 US · knowledge@plaintext.click