Diet Tetris (Take 2)

Geometry Level 5

Using any rotation of the L-shape and straight piece below:

there are exactly 5 5 ways that a 2 × 8 2 \times 8 box can be completely tiled:

Find the number of ways a 2 × 100 2 \times 100 box can be completely tiled by using any rotation of the L-shape and straight piece above.


The answer is 20365011074.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Atomsky Jahid
Jul 5, 2020

Tiling problems are related to Fibonacci sequences and recursion, and hence are very suitable for the application of dynamic programming.

First, think of the 2 × 100 2 \times 100 box as a collection of 25 25 small boxes of size 2 × 4 2 \times 4 . We will start tiling from the leftmost box and consider one box at a time. We define the number of ways the n t h n^{th} box can be filled with no overreach as j a r [ n ] [ 0 ] jar[n][0] and the number of ways it can be filled with overreach as j a r [ n ] [ 1 ] jar[n][1] .

Whenever we try to fill a particular box (say, ( n + 1 ) t h (n+1)^{th} box), we can have 2 2 possible initial states. In one state, the box will be empty initially. In the other case, it will have overreach from the previous box (in this case, the n t h n^{th} box). So, in how many ways can we fill the ( n + 1 ) t h (n+1)^{th} box?

If we want to fill the box with no overreach, we can do it in 2 j a r [ n ] [ 0 ] + j a r [ n ] [ 1 ] 2 \cdot jar[n][0] + jar[n][1] ways. And, if we want fill it with overreach, the number of ways will be j a r [ n ] [ 0 ] + j a r [ n ] [ 1 ] jar[n][0] + jar[n][1] . Hence, we get the following recursive relations.

j a r [ n + 1 ] [ 0 ] = 2 j a r [ n ] [ 0 ] + j a r [ n ] [ 1 ] jar[n+1][0] = 2 \cdot jar[n][0] + jar[n][1] j a r [ n + 1 ] [ 1 ] = j a r [ n ] [ 0 ] + j a r [ n ] [ 1 ] jar[n+1][1] = jar[n][0] + jar[n][1]

with the initial conditions

j a r [ 0 ] [ 0 ] = 1 jar[0][0] = 1 j a r [ 0 ] [ 1 ] = 0 jar[0][1] = 0

Here, what we want to find is j a r [ 25 ] [ 0 ] jar[25][0] .

N.B. I implemented the 2d array in a 1d list.

1
2
3
4
5
6
7
jar = [1, 0]

for i in range(25):
    jar.append( 2*jar[2*i] + jar[2*i+1] )
    jar.append( jar[2*i] + jar[2*i+1] )

print(jar[50])

Lovro Cupic
Jul 2, 2020

Let f ( n ) f(n) be the number of fully tiled 2 x 4n boxes and g ( n ) g(n) the number of "overtiled" 2 x 4n boxes, such as this one (overtiled 2 x 4 box) Then for each fully tiled 2 x 4n box we can add one purple or \textbf{or} one blue 2 x 4 block to get a fully tiled 2 x 4(n + 1) box. Also, for each overtiled 2 x 4n box we can add one L - shape to get a fully tiled 2 x 4(n+1) box. The recurrence relation for f ( n ) f(n) is therefore f ( n + 1 ) = 2 f ( n ) + g ( n ) f(n+1) = 2 f(n) + g(n) . Another equation is for overtiled boxes, which can be made either by adding an L - shape after a fully tiled sequence or \textbf{or} a Z - shape (two misaligned purple bars) after an overtiled sequence. Thus, second equation is g ( n + 1 ) = f ( n ) + g ( n ) g(n+1) = f(n) + g(n) . Initial conditions are f ( 1 ) = 2 f(1)=2 and g ( 1 ) = 1 g(1)=1 . Wolfram Alpha successfully solves such systems (even the free version). The answer is f ( 25 ) = 20365011074 f(25)=20 365 011 074 .

Chris Lewis
Jul 2, 2020

Let t ( n ) t(n) be the number of ways of tiling a 4 n × 2 4n \times 2 box. Say a tiling has a "vertical break" if we can split it into a tiling of a 4 k × 2 4k \times 2 box and a 4 ( n k ) × 2 4(n-k) \times 2 box, where 0 < k < n 0<k<n , without cutting a tile. A couple of observations first:

1) There are two ways to tile a 4 × 2 4 \times 2 box with no vertical breaks 2) There is a unique way to tile a 4 n × 2 4n \times 2 box with no vertical breaks for n > 1 n>1 (see the last picture in the question for an example)

From this we can build a recurrence for t ( n ) t(n) : there is 1 1 way to tile the whole box with no vertical breaks. There are 2 t ( n 1 ) 2t(n-1) tilings in which the first vertical break from the left creates a 4 × 2 4 \times 2 box. Then there are t ( n k ) t(n-k) tilings whose first vertical break from the left creates a 4 k × 2 4k \times 2 box, where 1 < k < n 1<k<n .

Putting all this together, we have t ( 1 ) = 2 t(1)=2 , t ( 2 ) = 5 t(2)=5 and t ( n ) = 1 + 2 t ( n 1 ) + k = 2 n 1 t ( n k ) t(n)=1+2t(n-1)+\sum_{k=2}^{n-1} t(n-k)

or, re-indexing the sum, t ( n ) = 1 + 2 t ( n 1 ) + k = 1 n 2 t ( k ) t(n)=1+2t(n-1)+\sum_{k=1}^{n-2} t(k)

Also, t ( n + 1 ) = 1 + 2 t ( n ) + k = 1 n 1 t ( k ) t(n+1)=1+2t(n)+\sum_{k=1}^{n-1} t(k) so that t ( n + 1 ) t ( n ) = 2 t ( n ) t ( n 1 ) t ( n + 1 ) = 3 t ( n ) t ( n 1 ) \begin{aligned} t(n+1)-t(n)&=2t(n)-t(n-1) \\ t(n+1) &= 3t(n)-t(n-1) \end{aligned}

This is enough to find the answer; we get t ( 25 ) = 20365011074 t(25)=\boxed{20365011074} .

But there's more! The first few values of t ( n ) t(n) are 2 , 5 , 13 , 34 , 89 , 2,5,13,34,89,\ldots - which are all Fibonacci numbers (in fact the sequence is every other Fibonacci number).

If F n F_n is the n n th Fibonacci number, we have F n = F n 1 + F n 2 F n + 1 = F n + F n 1 F n + 2 = F n + 1 + F n \begin{aligned} F_n &=F_{n-1}+F_{n-2} \\ F_{n+1} &=F_n+F_{n-1} \\ F_{n+2} &=F_{n+1}+F_n \end{aligned}

By eliminating F n 1 F_{n-1} and F n + 1 F_{n+1} we find F n 1 = F n F n 2 F n + 1 = F n + ( F n F n 2 ) = 2 F n F n 2 F n + 2 = ( 2 F n F n 2 ) + F n = 3 F n F n 2 \begin{aligned} F_{n-1} &= F_n-F_{n-2} \\ F_{n+1} &= F_n + (F_n-F_{n-2}) = 2F_n-F_{n-2} \\ F_{n+2} &=(2F_n-F_{n-2})+F_n = 3F_n-F_{n-2}\end{aligned}

which - together with the first two values of t ( n ) t(n) - proves that t ( n ) = F 2 n + 1 t(n)=F_{2n+1} . So in particular t ( 25 ) = F 51 t(25)=F_{51} .

Can anyone provide a more direct explanation for why Fibonacci numbers appear here? It's interesting that the number of ways of tiling a n × 2 n \times 2 box with dominoes is also a Fibonacci number.

Chris Lewis - 11 months, 2 weeks ago

Log in to reply

Not sure if it is what you are looking for, but I posted my solution that explains a little bit about why Fibonacci numbers appear in this problem.

David Vreken - 11 months, 2 weeks ago
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int number;
    cout << "Give the length of the rectangle: ";
    cin >> number;
    if(number%4!=0){
        cout << 0;
        return 0;
    }
    number/=4;
    vector<long long int> solution;
    solution.push_back(2);
    for(int x=1;x<number;x++){
        solution.push_back(2*solution[x-1]+1);
        for(int y=2;y<=x;y++){
            solution[x]+=solution[x-y];
        }
    }
    cout << solution[number-1];
    return 0;
}

David Vreken
Jul 2, 2020

Filling in pieces from left to right, there are only 4 4 different combinations that can be added to completely fill the grid:

If the rightmost piece ends evenly, A A or D D can be used next, but if the rightmost piece ends unevenly, B B or C C can be used next. If A A is used next then the rightmost number of pieces increases by 3 3 , if B B is used next then the rightmost number of pieces increases by 1 1 , if C C is used next then the rightmost number of pieces increases by 4 4 , and if D D is used next then the rightmost number of pieces also increases by 4 4 .

If A n A_n is the number of ways a sequence with a length of n n ends in A A , B n B_n is the number of ways a sequence with a length of n n ends in B B , C n C_n is the number of ways a sequence with a length of n n ends in C C , and D n D_n is the number of ways a sequence with a length of n n ends in D D , we have the following relationships:

A n + 3 = B n + D n A_{n + 3} = B_n + D_n

B n + 1 = A n + C n B_{n + 1} = A_n + C_n

C n + 4 = A n + C n C_{n + 4} = A_n + C_n

D n + 4 = B n + D n D_{n + 4} = B_n + D_n

where A 3 = 1 A_3 = 1 , B 4 = 1 B_4 = 1 , C 3 = 0 C_3 = 0 , and D 4 = 1 D_4 = 1 .

With a little manipulation, B n + 1 = A n + C n = ( B n + D n ) + ( A n 1 + C n 1 ) = B n + D n + B n = B n + D n + 4 B_{n + 1} = A_n + C_n = (B_n + D_n) + (A_{n - 1} + C_{n - 1}) = B_n + D_n + B_n = B_n + D_{n + 4} , or B n = D n + 4 + B n B_n = D_{n + 4} + B_n .

Using D 4 = 1 D_4 = 1 , B 4 = 1 B_4 = 1 , D n + 4 = B n + D n D_{n + 4} = B_n + D_n , and B n = D n + 4 + B n B_n = D_{n + 4} + B_n , the first few terms are ( D 4 , B 4 , D 8 , B 8 , D 12 , B 12 . . . ) = ( 1 , 1 , 2 , 3 , 5 , 8 , . . . ) = ( F 1 , F 2 , F 3 , F 4 , F 5 , F 6 , . . . ) (D_4, B_4, D_8, B_8, D_{12}, B_{12}...) = (1, 1, 2, 3, 5, 8, ...) = (F_1, F_2, F_3, F_4, F_5, F_6, ...) , the Fibonacci sequence. Therefore, D n = F 1 2 n 1 D_n = F_{\frac{1}{2}n - 1} and B n = F 1 2 n B_n = F_{\frac{1}{2}n} for n n values that are multiples of 4 4 .

A completed grid will end with either B B or D D for a total of S n = D n + B n = F 1 2 n 1 + F 1 2 n = F 1 2 n + 1 S_n = D_n + B_n = F_{\frac{1}{2}n - 1} + F_{\frac{1}{2}n} = F_{\frac{1}{2}n + 1} ways.

Therefore, for a 2 × 100 2 \times 100 grid, there are S 100 = F 1 2 100 + 1 = F 51 S_{100} = F_{\frac{1}{2}\cdot 100 + 1} = F_{51} ways to fill it. Using Binet's formula, that means there are F 51 = 1 5 ( ( 1 + 5 2 ) 51 ( 1 5 2 ) 51 ) = 20365011074 F_{51} = \frac{1}{\sqrt{5}}((\frac{1 + \sqrt{5}}{2})^{51} - (\frac{1 - \sqrt{5}}{2})^{51}) = \boxed{20365011074} ways to fill the 2 × 100 2 \times 100 grid.

Aha, so there's the Fibonacci relation. Silly question perhaps, but what exactly do the A n A_n denote? (I think you missed something defining these)

Chris Lewis - 11 months, 2 weeks ago

Log in to reply

It's the number of ways a sequence with a rightmost length of n n ends in A A . I'll edit that in.

David Vreken - 11 months, 2 weeks ago

Thank you! Until this moment I don't know that we can calculate the nth term of the Fibonacci sequence.

A Former Brilliant Member - 11 months, 1 week ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...