Answer the question
In order to leave comments, you need to log in
PHP backpack problem. How to pack forms?
I have rectangles and squares with sizes:
1x1, 1x2, 2x2.
It is necessary to pack arbitrary figures (they can be any, with repetitions) of these sizes into a 4x3 box as efficiently as possible.
The 1x2 figure, if necessary, must be turned over into a 2x1.
I read the task about the backpack, I saw it, I looked at the algorithms, but I couldn’t find it in PHP.
Maybe someone could at least point to the key to solving the problem?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
The task of the knapsack is generally NPcomplete, in PHP it will be considered for centuries. In your particular formulation, the problem is solved without intricate algorithms. Consider it a reference package - two large squares (they won't fit anymore) on which two sticks lie (they won't fit anymore). Further, the large square can be replaced by two sticks, and the stick by two small squares - this way you get a tree of all optimal solutions. It is small.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question