PiHan is a die-hard Pokemon Go player.
In his town, there are 16 PokeStops, including his own house which is also one! Being the busy problem solver on Brilliant, he wants to route through them in the fastest possible way, and come back to his house. He does not want to pass through a PokeStop on his route more than once.
What is the minimum number of minutes he would be spending on this tour?
Here is the matrix of the number of minutes it takes to travel from a pokestop to another. The th entry on the th line is the distance in minutes from stop to stop . PiHan's house is stop 1.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This problem is admittedly an instance of the Travelling Salesman Problem .
The naive solution is to check out all possible tours. This is O(n!) and obviously takes too long. We'll use Held-Karp's Algorithm to provide a O ( n 2 2 n ) dynamic programming solution.
Because we know that PiHan starts from the first stop, we could say that the tour begins and ends there. Consider subsets S ⊆ {2, . . . , N} of stops and, for c ∈ S, let D(S, c) be the minimum distance, starting at city 1, visiting all stops in S and finishing at city c. The recursive step is as follows:
D ( S , c ) = { d i s t 1 , c min { D ( ( S ∖ c ) , j ) + d i s t j , i } if S = { c } o t h e r w i s e
We can now code this up