#P2437. Bee Honeycomb Paths

    ID: 15708 Type: Default 1000ms 256MiB

Bee Honeycomb Paths

Bee Honeycomb Paths

A bee is crawling on a honeycomb whose cells are numbered as shown in the diagram below. It is known that the bee can only move from a cell with a smaller number to an adjacent cell with a larger number. In particular, if the bee is in cell \(k\), it may only move to one of its adjacent cells \(j\) such that \(j > k\). (Note: there is a small correction in the diagram – the cell at the top-right should be labeled \(n-1\) instead of \(n\)).

Now, given the starting cell \(m\) and the destination cell \(n\) with \(m .

Hint: Due to the structure of the honeycomb and the restriction that the bee only moves to a cell with a greater number, the number of routes from \(m\) to \(n\) follows a Fibonacci-like recurrence. In particular, if we denote \(dp[i]\) as the number of paths from cell \(m\) to cell \(i\), then we have:

[ \begin{aligned} dp[m] & = 1,\ dp[m+1] & = 1,\ dp[i] & = dp[i-1] + dp[i-2] \quad \text{for } i \ge m+2, \end{aligned} ]

Output \(dp[n]\) as the answer.

inputFormat

The input consists of a single line containing two integers \(m\) and \(n\) (with \(m < n\)) separated by a space.

outputFormat

Output a single integer which is the number of distinct routes from cell \(m\) to cell \(n\) following the rules described above.

sample

1 2
1