Let there be a set of objects, each of which has two parameters, weight and value. The backpack also has a certain capacity. The challenge was to pack a bag with a maximum value of objects inside, while respecting the constraint of a backpack on the total weight. All items are unique.

How to solve the task about a backpack, if the backpack is limited not only by capacity but also by the number of items that can be put (and the number of items must be equal to this limit, no more and no less)?