I have looked around my fellow's posts. There are mainly 3 solutions.
- Just use DFS, recursive call the function.
- Try to use some memorization like map.
- DP. I just see one solution using a 6D matrix to implement DP. Well, brilliant!.
All of them works for this small scenario, what if the problem is bigger? Which one do you think is the best? Or some other methods? Why?