Divide into to 2 groups by n/2 elements each and find for each group a solution with your O(3^n) algo! I have not yet tried this problem but I think it will be right idea!
not a counter, I use it for the lenght of the string which make this hash!
Then sort and it easy to find the answer! So the complexity is O(n*(n-1)/2)*logN or O(n^2logN)
There is a service route which start at 0 and ends in (C-1) and the path is 0->1 then 1->2 .......x->(c-1)
So if you reach some city in this path you should follow only this path to reach (c-1)!