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 1095 Solution Discussion