Problem list
Log in
#icpc00015 · ICPC World Finals 2012

Fibonacci Words

Diamond V 3.0 s 1024 MB

The Fibonacci word sequence of bit strings is defined as: $F$($n$) =    if $n = 0$ if $n = 1$ $F$($n - 1$) + $F$($n - 2$) if $n \ge 2$ He$re + de$notes concatenation of strings. The first few elements are: $n$ $F$($n$) 101 10110 10110101 1011010110110 101101011011010110101 1011010110110101101011011010110110 1011010110110101101011011010110110101101011011010110101 Given a bit pattern $p$ and a number $n$, how often does $p$ occur in $F$($n$)?

Input

The first line of each test case contains the integer $n$ ($0 \le n \le 100$). The second line contains the bit pattern $p$. The pattern $p$ is nonempty and has a length of at most 100 000 characters.

Output

For each test case, display its case number followed by the number of occurrences of the bit pattern $p$ in $F$($n$). Occurrences may overlap. The number of occurrences will be less than $2^{63}$.

Example 1

Input
6
10
7
10
6
01
6
101
96
10110101101101
Output
Case 1: 5
Case 2: 8
Case 3: 4
Case 4: 4
Case 5: 7540113804746346428
Source
ICPC World Finals 2012
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code