B
B
br1an2015-05-08 16:46:11
PHP
br1an, 2015-05-08 16:46:11

Algorithm for selecting N items by price?

Good day, dear)
Faced the following task:
For example, we have 4 items (it can be as many as you like) and their price
is 1 - 5p
2 - 10p
3 - 5p
4 - 10p
The task is this, select items from here so that they satisfied the condition: the sum of the selected items = 30% (+ -5% (for example) of the total amount of items.
In this case, the following combinations are possible: 1.3 and 2. (The combination with a smaller number of items is in priority)
That is, you need get the combination of items as close as possible to N% of the total amount.Has
anyone come across similar algorithms?
Any examples of solutions/algorithms?
I suppose that first you need to build all combinations without repetitions, and from them already choose the most suitable combination?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bobrovskyserg, 2015-05-08
@br1an

The task of laying a knapsack .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question