|
|
back to boardShow all messages Hide all messagesTaking hints from the forum I am using dynamic programming with bitmasking. But I cannot understand how to memoize the results as the number of subproblems are very large. ie. 2^n * m that is 2^20 * 120. I am getting Memory limit exceeded. Is there a better way to define the states of the dp? Yes. You have the matrix dp[120][2^20]. There is only transitions from n-th to (n+1)-th row of the matrix. So, you need to memorize only 2 rows (previous and current) instead 120. There is solution with only 2^n memory (not 2 arrays, but just one) |
|
|