I modified my bfs() and got it AC in 0.04 seconds.
Larry wrote:Use dynamic programming by first finding a recurrence..
Can someone give some detail about this recurrence relation. I think most of the people used Larry's method.
I also saw many people taking a considerable time to solve this problem. So is there any method other than exhaustive BFS().