↵
You can view the full, well-formatted C++ source code of Monte Carlo method here on GitHub:↵
↵
https://github.com/yawn-lento/yawn
↵
As for DFS, using iteration and recursion does make a crucial difference: we no longer waste our time on same paths, instead memory mechanism is introduced. However, we still have to try every single paths when the number grows exponentially, ending up in TLE.↵
↵
You can view the full, well-formatted C++ source code of DFS method here on GitHub:↵
↵
https://github.com/yawn-lento/yawn-s-codes/blob/main/P1002-DFS%E5%B0%9D%E8%AF%95.cpp
↵
↵
You can view the full, well-formatted C++ source code of DP method here on GitHub:↵
↵
https://github.com/yawn-lento/yawn-s-codes/blob/main/P1002-DP.cpp




