Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A small town has a rectangular grid of streets, shown in the figure. Junction is at the bottom left corner, and junction is blocks east and blocks north of . A courier always takes a shortest route from to , so each block she walks takes her one block east or one block north. We write a route as a word of letters, using E for a block east and N for a block north, in the order she walks them. So every route has letters E and letters N.
A turn is a place in the word where the letter changes, from E to N or from N to E. For example, the route EENNNEEEEEN, drawn in the figure, makes turns. Junction , blocks east and blocks north of , is also marked.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. A route is a word in E and N. For the turns, look at the runs of the word: the longest blocks of equal letters.
(a) A route is fixed by the places of its letters N among its letters: routes.
(b) A route through goes from to ( letters E and letters N, ways) and then from to ( E and N, ways). So routes pass through , and avoid it.
(c) A route with turns has runs, and the runs alternate between E and N. With turns there are runs. If the first run is E, the runs are E, N, E, N, E: three runs of E and two runs of N. Cutting the letters E into non-empty runs means choosing of the gaps between them, ways. Cutting the letters N into runs means choosing of gaps, ways. That gives routes. If the first run is N, there are three runs of N and two runs of E: routes. In all, .
(d) The runs alternate, so the numbers of E runs and N runs differ by at most . There are only letters N, so at most runs of N, and then at most runs of E. That is at most runs, or turns. Exactly turns needs runs of E and runs of N, so the route starts and ends with E and every N stands alone. The letters E are cut into runs in ways, and the N runs are forced. So the greatest number of turns is , made by routes.
(e) Proof. A route with exactly turns has runs. This number is odd, so the first run and the last run have the same letter.
Case 1: the route starts with E. Then it has runs of E and runs of N. The lengths of the E runs are positive whole numbers that add up to , in order. Such a list is fixed by choosing which of the gaps between the letters E are cuts, so there are lists. In the same way the lengths of the N runs can be chosen in ways. Once both lists are chosen the word is fixed, because the runs alternate and start with E. So Case 1 gives routes.
Case 2: the route starts with N. Now there are runs of N and runs of E, which gives routes.
Every route with turns is in exactly one case, so the total is the sum of the two terms. Both terms are needed because a route may start in either direction, and the two directions have different numbers of letters ( and ), so the two cases do not give the same count. For the formula gives , as in (c).
Check. Listing all 330 words and counting their turns gives the same numbers for every number of turns, and the same 180 routes that miss .
Log in to join the discussion.
Loading…
With Standard, you also open 12 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.