Answer the question
In order to leave comments, you need to log in
How to solve problems on this type of DP (choose items, but without repetitions)?
There is a task: https://cses.fi/problemset/task/1158
I understand how to do when you can repeat items, but when you can’t, I don’t understand how.
I will be grateful for the answer.
Answer the question
In order to leave comments, you need to log in
This is a classic knapsack problem.
We can compose the following DP: F(c, k) - the maximum number of pages that can be typed from the first k books with a total cost of exactly c.
Base: F(0,0) = 0, F(0,*) = F(*,0) = -infinity.
Recalculation:
F(c, k) = max(F(c-cost[k], k-1) + pages[k], F(c,k-1))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question