Editorial for COCI '07 Contest 1 #4 Zapis
Submitting an official solution before solving the problem yourself is a bannable offence.
We start by observing the first character in the sequence. That character must be an opening bracket. Its closing bracket can only be located at an even position in the sequence (because a regular bracket sequence has even length).
For each even position , and for each type of bracket, we now check if it is possible to place an opening bracket as the first character and a corresponding closing bracket as character. If it is possible then we add to the total number of solutions the number of regular bracket-sequences from the second character to character multiplied by the number of regular bracket-sequences from character to the last character.
By doing this we have reduced the large problem to two smaller subproblems of the same type, so it can be solved using dynamic programming or memoization.
Comments