Cutting a $m \times n$ rectangle into $a \times b$ smaller rectangular pieces

How many $a \times b$ rectangular pieces of cardboard can be cut from $m \times n$ rectangular piece of cardboard so that the amount of waste("left over" cardboard) is a minimum?

This question was given to me by my Mathematics Teacher as a "brain teaser".

At first I divided $m \times n$ by $a \times b,$ but then I realized that it is not possible in the given situation, as the "left over" cardboard will also be "divided" among $a \times b$.

Next I tried started thinking it terms of perimeter. I imagined all the $a \times b$ rectangles lying side by side in a "rows and columns" format(sort of a grid), without any space between them, thus forming another rectangle/square. I assumed $\lambda$ rows and $\sigma$ columns of those smaller rectangles. After a bit of calculations, my answer came out as following :

Number of smaller $a \times b$ rectangles $\geq \sigma \times \lambda$ = $\left(\dfrac {m - m \, mod \, a }{a}\right) \times \left(\dfrac {n-n\, mod \, b}{b}\right).$

Is my "second" approach correct ?

Is there any alternate way of tackling this problem?

This might seem a 'vague' question, but can this problem be generalized to any given shape ?

Any help will be gratefully acknowledged :).

• – Simply Beautiful Art Jan 28 '17 at 15:22
• @SimplyBeautifulArt That does not seem to help a lot ... one answer says Without Loss Of generality assume boxes to be distinct.... By the way is my approach correct ??? – Nirbhay Jan 28 '17 at 15:24
• I don't believe there is any known way to calculate this with a direct formula, and BeaitifulArt's link seems to agree. – Kaynex Jan 28 '17 at 15:33
• @Kaynex Is my approach OK ??? – Nirbhay Jan 28 '17 at 15:39
• You've asked twice if your approach is "OK". I'd say it's a good start, but it leaves a lot of cases untested. You might imagine a situation where you lay a row of $a\times b$ rectangles length-wise, but then another row turned 90 degrees. Maybe $3a + 5b = m$, so by laying 3 rows one way and 5 rows the other way, you end up with no waste in the $m$ direction. The point is that there are infinity minus one things to think about here. – B. Goddard Jan 28 '17 at 18:32

The approach proposed in the OP may be good, as it gives a waste $W$ of

$$W=(m \mod{a}) \cdot n + (n \mod { b}) \cdot m - (m \mod { a} ) ( n \mod {b})$$

that in most cases is distributed along two adjacent sides. For example, let us take a $120\times 100$ rectangle to be filled with $11\times 7$ rectangles. Using the approach of the OP, the waste is

$$W=(120 \mod 11) \cdot 100 + (100 \mod 7) \cdot 120 - ( 120 \mod 11 )\cdot ( 100 \mod 7) \\ =10 \cdot 100 + 2 \cdot 120 - 10 \cdot 2=320$$

However, I believe that there could be a potentially better strategy. We could assess whether one between $m$ and $n$ can be expressed as $ax+by$, where $x$ and $y$ are integers. If this is the case, we can leave an incomplete region only along a single side of the large rectangle (instead of two). For instance, in the example above, we can note that $120$ can be expressed as $$120=99+21=9 \cdot 11 +3\cdot 7 \,\,\,\,$$ So, dividing the sides equal to $120$ in two parts measuring $99$ and $21$, we can divide the initial rectangle in two rectangles ( $99 \times 100$ and $21 \cdot 100$). The first one can be filled beginning from the side equal to $99$, placing a first sequence of $9$ small rectangles (oriented as $11 \cdot 7$) to cover a $99 \times 7$ area, then another sequence to achieve a $99 \times 14$ area, and so on, arriving to a $99 \times 98$ area. This leaves a partial waste of $2 \cdot 99=198$. The second one can be filled beginning from the side equal to $21$, placing a first sequence of $3$ small rectangles (oriented as $7 \cdot 11$) to cover a $21 \times 11$ area, then another sequence to achieve a $21 \times 22$ area, and so on, arriving to a $21 \times 99$ area. This leaves a partial waste of $1 \cdot 21=21$. The total waste is $198+21=219$. Generalizing, if we can set $m=ax+by$, the waste with this approach is $$W=ax \cdot (n \mod b) + by \cdot (n \mod a)$$

There are several points to be highligted in this solution. First, this approach should be attempted by considering all possibilities of expressing $m$ or $n$ as $ax+by$, and choosing the one that minimizes the waste. In the example used before, other two possibilities could be to set $$m=120=2 \cdot 11 + 14 \cdot 7\,\,$$ or $$n=100=4 \cdot 11 + 8 \cdot 7\,\,$$ Using the same procedure, it can be easily shown that these choices lead to wastes of $142$ and $604$, respectively. Among all three possibilities, that leaving $142$ gives the best solution. Second, even if this approach allows a nearly full packing along three sides, it does not always produce a minor waste than the solution suggested in the OP. The case $W=604$ described above is an example of this. Also note that the solution of the OP could be applied after rotating the initial rectangle by $90^o$ to get

$$W=(100 \mod 11) \cdot 120 + (120 \mod 7) \cdot 100 - ( 100 \mod 11 )\cdot ( 120 \mod 7) \\ =1 \cdot 120 + 1 \cdot 100 - 1 \cdot 10=210$$

which is a better result than that initially obtained. Lastly, note that a "complete" packing (with no waste) can be obtained only in two scenarios, that is to say 1) $a$ divides $m$ and $b$ divides $n$ (or alternatively $a$ divides $n$ and $b$ divides $m$), 2) both $a$ and $b$ divide one (the same) of $m$ and $n$, for example $m$, and the other (in this example $n$) is of the form $n=ax+by \,\,\,$ with $x,y$ integers.

A simple example, for $a=2, b=3$, and a few values for $n$ and $m$ shows that the problem is not easily approachable, specially in the last configuration.

It is in fact a Cutting Stock Problem as rightly indicated by @sas, however simplified by having rectangular and fixed size items.
It is quite an interesting subject, so starting from the sketch above, let's try and establish some facts about,
without pretending to be rigourous and to provide proofs.
Premised that we use the following symbols, for the integral and fractional part and for modulus $$\begin{gathered} x = \left\lfloor x \right\rfloor + \left\{ x \right\} \hfill \\ \frac{x} {t} = \left\lfloor {\frac{x} {t}} \right\rfloor + \left\{ {\frac{x} {t}} \right\} \hfill \\ x = t\left\lfloor {\frac{x} {t}} \right\rfloor + t\left\{ {\frac{x} {t}} \right\} = t\left\lfloor {\frac{x} {t}} \right\rfloor + x\bmod t \hfill \\ \end{gathered}$$ then

1. Upper bound for $N$
Clearly we must have $N a b \leqslant nm$, i.e. $$\bbox[lightyellow]{ N \leqslant \left\lfloor {\frac{{n\,m}} {{a\,b}}} \right\rfloor = \left\lfloor {\,\frac{{n\,m/\gcd (nm,ab)}} {{a\,b/\gcd (nm,ab)}}} \right\rfloor = \left\lfloor {\frac{{n'\,}} {{a'}}\,\frac{{m'}} {{b'}}} \right\rfloor \tag {1} \\ }$$ This also indicates an equivalence in the problem when the parameters are scaled so as to keep the ratio $(nm)/(ab)$ constant, and that we can always reduce the parameters and get $n$ and $m$ be coprime vs. $a$ and vs. $b$.
But, geometrically speaking, the down-scaling looks to be applicable only if $max(a',b') \leqslant min(n',m')$.
An example is given in this sketch
2. Equivalence under rotation, reflection
Clearly the problem does not change under rotation or reflection.
3. "Cross histogram"
Consider to take a horizontal scan and to record, per each unit row, the number of layers of horizontal dimension $a$ and $b$ traversed. Let's do the same on a vertical scan.
Clearly, every $b$ counts for a layer of width $a$ in one direction will correspond to $a$ counts for $b$ in the other direction. And viceversa.
4. Conclusions
Condensing all the considerations above we are led to claim the following:
a) Among the various possible partitions of $m$ and $n$ (in case $n'$, $m'$) as a linear combination of $a$ and $b$, with non-negative integral coefficients, as $$\bbox[lightyellow] { \left\{ \begin{gathered} n = n_{\,a} a + n_{\,b} b + n_{\,r} \hfill \\ m = m_{\,a} a + m_{\,b} b + m_{\,r} \hfill \\ \end{gathered} \right. \tag {2} }$$ we shall choose those which, while giving minimal remainder ($n_r,m_r$), also assure best symmetry around $n/2$,$m/2$, that is $$\bbox[lightyellow] { \left\{ \begin{gathered} n_{\,a} a \approx n/2 \approx n_{\,b} b \hfill \\ m_{\,a} a \approx m/2 \approx m_{\,b} b \hfill \\ \end{gathered} \right. \tag {3} }$$
b) Note that the above goal of symmetry is to be achieved globally on $n$ and $m$, so that it happens that we shall compromise somehow on one of the parameters, to keep the best on the other. When that happens, for the unbalanced parameter we are asked to choose two partions on the opposite sides of the symmetry, so that they make an optimal one on average, in case inserting a remainder if necessary (re. to the case $n=4,m=5$ in the first sketch). So, practically, we are determining a pair of partitions for each parameter.
c) The above situation can be faced when $n,m$ are relatively small with respect to $a,b$. When they are much larger than $a,b$ then a partion (or two on average) close to symmetry can be found for both.

Therefrom a possible strategy seems to be as follows (you can follow the process on one of the sketches given)

• repart one side of the rectangle (e.g. $m$) according to one of its pair of partitions, putting first all the $a$'s, then the remainder, then the $b$'s;
• following the perimeter, repart the contiguous side ($n$), this time starting with the $b$'s;
• pass to next side ($m$), and apply the remaining partition of the pair associated with $m$;
• same for the last side;
• expand the partition of the perimeter towards the inner part, as allowed

From the examples, it looks that it is possible to reach $N= \left\lfloor {\frac{{n\,m}}{{a\,b}}} \right\rfloor$ in "many" cases.

• @G Cab Which software did you use ???? Do you have any idea how to solve the problem ??? – Nirbhay Feb 2 '17 at 11:12
• @Nirbhay I did the sketch by hand, trying to validate a possible approach, which unfortunately does not work for particular values of $m$ and $n$ as shown. However it provides upper and lower bounds: I will add it to my answer, as it might interest you anyway. – G Cab Feb 2 '17 at 11:38
• How can you possibly "sketch" that "by hand" ???? – Nirbhay Feb 2 '17 at 11:48
• How many $2\times 2$ squares can you fit into a $3\times 3$ square? Certainly no more than $1$, despite the fact that $\lfloor(9/4)\rfloor=2$. – mjqxxxx Feb 8 '17 at 15:41
• @RobertFrost: yes, that's the case if we admit that $a$ or $b$ can be larger than $n,m$: that opens a quite different scenario. – G Cab Feb 9 '17 at 19:39