|
|
back to boardHow to use dynamic programming with bitmasking? Taking 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? Re: How to use dynamic programming with bitmasking? Posted by Helgui 25 Dec 2013 19:24 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. Re: How to use dynamic programming with bitmasking? There is solution with only 2^n memory (not 2 arrays, but just one) |
|
|