UVa 10818 - Dora Trip

10818 - Dora Trip

 * http://acm.uva.es/p/v108/10818.html

Summary
Variant of Traveling Salesperson Problem.

Explanation
This problem is NP-complete. But since the number of places that Nobita has to visit is no more than 10, a simple search suffices. Note that we ask for the lexicographically smallest shortest path.

The I/O below is taken from http://online-judge.uva.es/board.

Gotcha's
Especially for C/C++ users: be careful of how your program reads the input.

Input
7 7 6 6 6 6 5 5 0 0
 * 1)  X X#
 * 2)  S *#
 * 1)  X X#
 * 2)  S *#
 * 1) X X#
 * 2) S *#
 * 1) X X#
 * 2) S *#
 * 1) S *#
 * 1) S *#
 * 2)  XX#
 * 1)  XX#
 * 1) S X#
 * 2) *X#
 * 1) *X#

Output
EESSWWWWNNNNEEEEWSSW EEENWNNEWWWESSSW EEEWWSSEESWWWNNN ESWSNN