ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1326. Bottle Taps

How to use dynamic programming with bitmasking?
Posted by Nikunj Banka 12 Oct 2013 21:21
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)