Red, Green or Blue Tiles
A row of five black square tiles needs to have a number of its tiles replaced with coloured oblong tiles chosen from: red tiles (length 2), green tiles (length 3), or blue tiles (length 4). If red...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
A row of five grey square tiles is to have a number of its tiles replaced with coloured oblong tiles chosen from red (length two), green (length three), or blue (length four).
If red tiles are chosen there are exactly seven ways this can be done.

If green tiles are chosen there are three ways.

And if blue tiles are chosen there are two ways.

Assuming that colours cannot be mixed there are \(7 + 3 + 2 = 12\) ways of replacing the grey tiles in a row measuring five units in length.
How many different ways can the grey tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used?
Problem 116: Red, Green or Blue Tiles
Mathematical Foundation
Theorem 1 (Single-color tiling recurrence). Let denote the number of ways to tile a row of length using unit black tiles and colored tiles of length (including the all-black tiling). Then:
with for .
Proof. Consider the rightmost position of a row of length . Either:
- It is covered by a black unit tile. The remaining prefix of length can be tiled in ways.
- It is covered by the right end of a colored tile of length . The remaining prefix of length can be tiled in ways.
These cases are mutually exclusive and exhaustive (every tiling ends with exactly one tile). For , only the all-black tiling is possible, giving .
Theorem 2 (Independence of colors). When colors cannot be mixed, the total count of tilings with at least one colored tile is:
Proof. Since colors cannot be mixed, the tiling must use exactly one color type. For each color with tile length , the number of tilings with at least one colored tile is (subtracting the all-black tiling). The three color choices are mutually exclusive, so the total is the sum.
Lemma 1 (Verification for ). , , , giving .
Proof. For : , , , , . For : , , , . For : , , . This matches the problem statement.
Theorem 3 (Connection to Fibonacci). where is the -th Fibonacci number with .
Proof. The recurrence with and is exactly the Fibonacci recurrence shifted by one index.
Editorial
Count ways to tile a row of 50 black squares using tiles of a single color (red=2, green=3, blue=4) without mixing colors, with at least one colored tile. We compute f_L(n).
Pseudocode
total = 0
For each L in {2, 3, 4}:
Compute f_L(n)
f = array of size n+1
For k from 0 to L-1:
f[k] = 1
For k from L to n:
f[k] = f[k-1] + f[k-L]
total += f[n] - 1
Return total
Complexity Analysis
- Time: per color, total (three passes of length ).
- Space: per color using a rolling window (since each depends only on and ), or with a full array.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
const int N = 50;
long long answer = 0;
// For each tile length L in {2, 3, 4}, compute f_L(N) - 1
for (int L = 2; L <= 4; L++) {
vector<long long> f(N + 1, 0);
for (int i = 0; i < L && i <= N; i++) f[i] = 1;
for (int i = L; i <= N; i++) {
f[i] = f[i - 1] + f[i - L];
}
answer += f[N] - 1;
}
cout << answer << endl;
return 0;
}
"""
Problem 116: Red, Green or Blue Tiles
Count ways to tile a row of 50 black squares using tiles of a single color
(red=2, green=3, blue=4) without mixing colors, with at least one colored tile.
"""
def count_tilings(n, L):
"""Count tilings of row length n with black (1) and colored (L) tiles."""
f = [0] * (n + 1)
for i in range(min(L, n + 1)):
f[i] = 1
for i in range(L, n + 1):
f[i] = f[i - 1] + f[i - L]
return f[n]
N = 50
answer = sum(count_tilings(N, L) - 1 for L in [2, 3, 4])
print(answer)