During the contest, I solved this problem using BFS with state [i, j, food] where i = row, j = column and food = letter I'm trying to grab.
To count the number of shortests paths, I filled a table paths[len][i][j][food] = number of different paths of length "len" ending at state [i, j, food].
However, my solution is rather slow. I've seen some people ranked with times < 0.010. What's the fastest method to solve this problem?


