The best over every range
transcript
Build logs sit in shards, in a row. Merging two neighbours costs their combined size. Which order copies the least?
Five shards have fourteen orders. Ten shards have 4,862. Twenty shards have over a billion.
In a bracket, the final splits the teams in two. Each half is a smaller bracket. The last merge splits the shards the same way. Plan the short ranges first.
A table holds one cell for every range. Short ranges are solved first. A long range joins the best of two shorter ones.
Twenty shards have 210 ranges. The table solves each range once. The five shards cost 53 at best.
Many orders contain the same range, such as shards three to six. Its best cost never changes, whatever happens outside. So solve it once, and keep the answer in a table. This is dynamic programming on ranges.
Solve each range once, short before long. Then the whole row is one more range. Full breakdown in the lecture.