(CSES) DP: recursion vs iterative

Revision en1, by TheAiro, 2023-03-29 12:37:06

Hi, I am having difficutlties with this CSES problem "Book Shop". Firstly I implemented it recursively, but it gave me TLE. (Link). I've also been trying to get into iterative dp, so I tried it too and it worked! (Link)

However, I don't understand why recursive approach doesn't pass. Maybe I have implemented it poorly?

Also, it seems that there is an approach with $$$O(x)$$$ space complexity, but I have no clue how it works.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English TheAiro 2023-03-29 12:37:06 598 Initial revision (published)