How to initialize dp[10001][10001]


this is my code which is failing 3 test cases as n<=10000
while on initializing 10001 * 10001 size i get line 4 killed…ex error
I tried to declare with new operator/pointer and then clueless about how to use memset ,
please help me in this question.

Check now =>


Also your code was clean so it was easy to debug.

It’s beneficial when you know all the test cases are of fixed length
For eg: let length of 1st test case be 10 & second be of 1000, so for 1000 length you are declaring dp[1000][1000] index as -1, which is fine. But why to do for length of 10? it needs only 1010 block size that is 100 but we are giving it 10001000 computation, thus resulting in TLE.

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.