Editorial for Baltic OI '05 P4 - Ancient Manuscript
Submitting an official solution before solving the problem yourself is a bannable offence.
Note that the original editorial was in Lithuanian and may have translation errors.
The problem is solved by generating all variants and applying dynamic programming, to avoid having to recompute everything.
A dynamic table is created; It shows the number of ways in which a phrase can be completed if:
- already completed up to and including the th letter;
- the th letter is ;
Counting backwards from the th letter (we have no idea what is happening at the beginning of the word only what happens at the end, i.e. at the point where we need to fill in from) is
- identical successive consonants
- consecutive consonants
- identical successive vowels
- consecutive vowels
For example, the initial phrase y*af
:
We filled it up to aayb
in a recursive way, i.e.
- ,
-
b
, - (ending in a single consonant
b
) - (ending in two consonants
yb
); - (no vowels at the end);
- .
Instead of all the *
's, we try to substitute all the possible letters from a
to z
. For each letter, we check whether it can be done (i.e. whether it does not exceed the set norms), and fill in the table. If we can take a look from the table, we take it from there. If not, it is calculated recursively and stored in the table.
Comments