Define dp[] = 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, dp[] = max(dp[], dp[-] + ) for all ≥ .
Process books one by one. Iterate budget in reverse ( from down to ) to avoid using the same book twice. Take time to work through examples. The pattern becomes clearer with practice. The state tracks both money spent and which books you have considered. Two dimensions are needed.