Answer the question
In order to leave comments, you need to log in
How to figure out an optimization algorithm?
In general, the essence is this - there are, for example, fruit baskets, the baskets are presented in this form:
М/К-мест в корзине, К/К -количество корзин.
М/К | К/К
---------
20 | 3
18 | 1
16 | 2
14 | 6
12 | 9
10 | 2
8 | 10
6 | 2
4 | 3
Answer the question
In order to leave comments, you need to log in
Sergey, look, this option may work (I will describe the general principle, the implementation of the code, of course, is up to you
) : 10 plums, 5 bananas).
2. You fill the baskets from top to bottom (from large volumes to smaller ones). You fill as much as possible - the entire basket, leave the rest aside for the time being, do not use it.
For example:
step 1: 30 apples and 3 baskets of 20... We fill 1 basket completely, save the rest of 10 apples for later, do not use now.
step 2: 25 pears and 2 baskets of 20... We fill 1 basket completely, save the rest of 5 pears for later, do not use now.
step 3:20 oranges and 1 basket of 20... We fill 1 basket completely, there is no remainder.
step 4: 15 tangerines and 1 basket of 18... SKIP, looking for an option to fill a FULL basket...
step 5: 15 tangerines and 2 baskets of 16.. SKIP, looking for an option to fill a FULL basket...
step 6: 15 tangerines and 6 baskets of 14 each ... We fill 1 basket completely, save the rest of 1 tangerine for later, we do not use it now.
etc. .........
You sort the final balances by quantity and run it again according to the same scheme, providing, of course, for the fact that it will be necessary to partially fill the baskets, because the number of residues will be small (units).
A top-down run is needed in order to rationally use the baskets - after all, if there is 1 apple and 2 baskets (20 and 4 places, respectively), it is logical to put it in a basket for 4 places.
Something like this. Of course, I am not an expert in native algorithms, perhaps there is some kind of "interpolation method of apparent variance" for solving such problems - here I pass :). What could...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question