Doubt in a question

In the yesterday codeforces round… in 2nd second question…
https://codeforces.com/contest/1427/problem/B
I have come up with a DP solution… I have used recursion + memoization …
This is my code…
But it was showing memory limit exceeded error in pretest-3.
can you see my code…
Where can be optimised this.
Is it even possible to solve this question with recursion+memoization.
This is my code.


Thanks

hello @ashishnnnnn

see the constraints
image

dp will never work on it , as we dont have that much space to memoise the result of 3d dp

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.