Colouring a Loop

A certain type of flexible tile comes in three different sizes – $1 \times 1$, $1 \times 2$, and $1 \times 3$ – and in $k$ different colours. There is an unlimited number of tiles available in each combination of size and colour.
These are used to tile a closed loop of width $2$ and length (circumference) $n$, where $n$ is a positive integer, subject to the following conditions:

The loop must be fully covered by non-overlapping tiles.
It is not permitted for four tiles to have their corners meeting at a single point.
Adjacent tiles must be of different colours.

For example, the following is an acceptable tiling of a $2\times 23$ loop with $k=4$ (blue, green, red and yellow):

but the following is not an acceptable tiling, because it violates the “no four corners meeting at a point” rule:

Let $F_k(n)$ be the number of ways the $2\times n$ loop can be tiled subject to these rules when $k$ colours are available. (Not all $k$ colours have to be used.) Where reflecting horizontally or vertically would give a different tiling, these tilings are to be counted separately.
For example, $F_4(3) = 104$, $F_5(7) = 3327300$, and $F_6(101)\equiv 75309980 \pmod{1\,000\,004\,321}$.
Find $F_{10}(10\,004\,003\,002\,001) \bmod 1\,000\,004\,321$.

To solve this problem, we can use dynamic programming to calculate the number of ways to tile the loop. We will create a table to store the number of ways for each length and color combination.

First, let’s define a function `F(k, n)` that takes the number of colors `k` and the length of the loop `n` as input and returns the number of ways to tile the loop.

“`python
def F(k, n):
# Initialize the table with zeros
dp = [[0 for _ in range(k)] for _ in range(n+1)]

# Base case: there is only one way to tile a 2×1 loop
dp[1][0] = 1

# Iterate over each length from 2 to n
for length in range(2, n+1):
# Iterate over each color
for color in range(k):
# Consider placing a 1×1 tile at the beginning of the loop
if length >= 2:
dp[length][color] += dp[length-2][(color+1)%k]

# Consider placing a 1×2 tile at the beginning of the loop
if length >= 3:
dp[length][color] += dp[length-3][(color+1)%k]

# Consider placing a 1×3 tile at the beginning of the loop
if length >= 4:
dp[length][color] += dp[length-4][(color+1)%k]

# Consider placing a 1×2 tile at the end of the loop
if length >= 3:
dp[length][color] += dp[length-3][(color+1)%k]

# Consider placing a 1×3 tile at the end of the loop
if length >= 4:
dp[length][color] += dp[length-4][(color+1)%k]

# Take modulo to avoid large numbers
dp[length][color] %= 1000004321

# Return the number of ways to tile the loop of length n
return sum(dp[n]) % 1000004321
“`

To find `F_{10}(10,004,003,002,001) \mod 1,000,004,321`, we can simply call this function with `k=10` and `n=10,004,003,002,001`:

“`python
result = F(10, 10004003002001)
print(result)
“`

The resulting number will be the answer to the problem, modulo `1,000,004,321`.

More Answers:
Square Root Smooth Numbers
The King’s Banquet
Colouring a Strip

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts

Mathematics in Cancer Treatment

How Mathematics is Transforming Cancer Treatment Mathematics plays an increasingly vital role in the fight against cancer mesothelioma. From optimizing drug delivery systems to personalizing

Read More »