Fibonacci Strings
Time limit1sMemory limit1024 MB
Sum the orders (counts of letter a) of every substring of X that is a Fibonacci string, meaning it has no two adjacent a's, counting each occurrence separately.
- Level
Hard8 of 10
- Topics
- String, Dynamic programming, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Aron likes Fibonacci numbers. He likes them so much that he got bored of the numbers themselves and decided to invent other combinatorial objects based on them instead.
His first invention is the Fibonacci string. A string consisting only of the letters and , with exactly letters and no two consecutive letters , is called a Fibonacci string of order .
Given a string of s and s, compute the sum of the orders of all Fibonacci strings that occur as substrings of . If a string occurs multiple times in , its order is counted once for each occurrence.
Input
The judge reads input in the following format:
- line :
N - line :
X
Output
The judge writes a single line containing the return value of fibonacci(N, X).