Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 E

Four cities have symmetric travel costs D = [[0, 27, 24, 21], [27, 0, 30, 17], [24, 30, 0, 1], [21, 17, 1, 0]]. Starting at city 0, you must visit every city exactly once and return to city 0 at the minimum total cost. What is that minimum cost?

  1. A. 79
  2. B. 69
  3. C. 72
  4. D. 74

Correct answer: B. 69

Bitmask DP: dp[mask][last] is the cheapest path from city 0 that visits exactly the cities in mask and ends at last. Greedy nearest-neighbour gives a good but not always optimal tour, and the answer adds the return leg to city 0.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic