Posts

Showing posts from January, 2025

British Algorithmic Olympiad 2024

Question 4. Colour Codes A The input is an array of 7 non-negative integers c ; sum(c) is the number $n$ of letters in the colour code. It is the case that some of the letters could be repeating as in the example given. To generate permutations straight insertion is a method that easy to code (and understand). If the string is $\tt{RRYB}$ we can pick the first character in the sequence. The one element array $\begin{array}{|c|}\hline \tt{R} \\ \hline \end{array}$ has two insertion points: before and after. However in this case both insertion points generate exactly the same permutation namely $\begin{array}{|c|c|}\hline \tt{R} & \tt{R} \\ \hline \end{array}$. As a general rule, if at an insertion point $i$, the character we are inserting is the same as the array element at that insertion point, we can skip the insertion. We can summarise the procedure using the following Python...

Stars and bars through recursion.

Problem: You are given a recursive relation \[ F(n,m)=\sum_{k=1}^n F(k,m-1) \tag{A} \] where $F(n,1)=n$. Show that \[ F(n,m)=\binom{m+n-1}{n-1}. \] Solution: Start by expanding the sum in $\text{(A})$: \[ F(n,m)=\sum_{k_1=1}^n \sum_{k_2=1}^{k_1} \cdots \sum_{k_{m-2}=1}^{k_{m-3}}\sum_{k_{m-1}=1}^{k_{m-2}} F(k_{m-1},1). \] Since $F(k_{m-1},1)=k_{m-1}$, \[ \sum_{k_{m-1}=1}^{k_{m-2}} F(k_{m-1},1)= \sum_{k_{m-1}=1}^{k_{m-2}} k_{m-1}=\frac{k_{m-2}(k_{m-2}+1)}{2} =\binom{k_{m-2}+1}{k_{m-2}-1}. \] The next sum is \[ \sum_{k_{m-2}=1}^{k_{m-3}}\binom{k_{m-2}+1}{k_{m-2}-1}; \] to evaluate this we will use the Egorychev method. Start with the first binomial coefficient integral \[ \binom{n}{k}=\frac{1}{2\pi i} \int_{\abs{z}=\varepsilon} \frac{(1+z)^n}{z^{k+1}} dz \] to write (replacing $k_{m-2}$ with $k$ and $k_{m-3}$ with $m$ for brevity) \[ \sum_{k=1}^{m}\binom{k+1}{k-1} = \sum_{k=1}^{m} \frac{1}{2\pi i} \int_{\a...

CSAT 1

Image
Test Section A 1. You have a card of 10cm by 10cm. What is the largest volume in cm 3 of a box (without a lid) that can be obtained by cutting out a square of side x from each corner and then folding the flaps up? We can obtain an idea of the solution by looking at the following diagram: The box will have a base (marked in red on the diagram) with area $(l-2x)^2$ and height $x$. Therefore the volume of this box will be \begin{equation*} V=(l-2x)^x. \end{equation*} To maximize the volume first calculate \[ \dv{V}{x}=-4(l-2x)x+(l-2x)^2 \] using the product rule $d(u\cdot v)=du \cdot v + u \cdot dv$. Solve for $\dv*{V}{x}=0$ to find a (potential) maximum. If we assume that $x\neq l$ (a reasonable assumption since $x=l/2$ creates a nothing box) then \begin{align*} -4(l-2x)x+(l-2x)^2& =0 \\ l-2x-4x & = 0 \\ x & = \frac{l}{6}. \end{align*} To check that this is i...