Kangaroo
Time limit2sMemory limit512 MB
Count the alternating-direction routes by which a kangaroo visits every cell of a row exactly once, starting at cs and ending at cf.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
A garden is one row of cells numbered 1 to . Every cell holds a plant at the start.
A kangaroo lands on cell and eats the plant there. After that it jumps from cell to cell, eats the plant in every cell it lands on, visits all cells exactly once, and stops on cell . The starting cell and the last cell count as visited, so the kangaroo makes exactly jumps.
To avoid being caught, the kangaroo changes the direction of its next jump after every jump. If it jumped from cell to cell and then jumps from cell to cell , both conditions below hold.
- If , then .
- If , then .
Given the number of cells , the starting cell , and the last cell , count the distinct routes the kangaroo can take.
Input
The first line contains the positive integers , , , separated by spaces.
- A route is determined by the order in which the cells are visited.
- Every input has at least one route that follows the rules.
- The kangaroo may make its first jump from cell in either direction.
Output
Print the number of distinct routes that follow the rules, modulo (), on one line.
Hint
In the first example the kangaroo starts on cell 2 and stops on cell 3. Two routes follow the rules: 2 → 1 → 4 → 3 and 2 → 4 → 1 → 3.