Define = maximum pages achievable with budget . This is the space-improved 1D (one-dimensional) version. For each book with price and pages : if we buy it, = max(, + ) for all ≥ .
Process books one by one. Iterate budget in reverse ( from down to ) to avoid using the same book twice. The state tracks both money spent and which books you have considered. Two dimensions are needed.