How to use Top-down DP?
Help me by providing a top-down dp solution for these two: first, second.
If there are any type of optimizations that manages it to run in 1s please elaborate.
Codeforces Round 945 Solution Discussion (with myself)
Atcoder ABC #354 Solution Discussion