this is my code… Please tell me how to solve this using 2D dp only, not 1D DP?
How to solve this using 2D dp?
Logic is absolutely correct, it just you can’t make such a long dp array, check this-> have shortened the size
100000 x 1000 = 10^8 will result in TLE
you initialize dp[n][sum] as of size dp[1001][1001] only. Then how it will store the value for a larger sum value(sum>1001) let say sum=10000 then, can we write dp[n][10000] = something?
In that case you would have to use 1d dp to avoid tle
You can do dp[n][10000] but make sure n*sum <=10^8 to avoid tle