Commute Route
InterviewTime limit1sMemory limit128 MB
Count monotone lattice paths from (1,1) to (w,h) that never turn at two consecutive intersections, modulo 100000.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
The city where Sang-geun lives has roads running north-south and roads running east-west.
The north-south roads are numbered from west to east, and the east-west roads are numbered from south to north. The intersection where the -th north-south road (counting from the west) meets the -th east-west road (counting from the south) is called .
Sang-geun lives at intersection and drives to his company at intersection . A car may travel only along the roads. To reach the company as quickly as possible, Sang-geun moves only east or north.
To reduce traffic accidents, the city forbids a car that has just turned at an intersection from turning again at the very next intersection. In other words, after changing direction a car may not move just one block and immediately change direction again; it must go straight for at least two blocks before it may turn again.
Given and , write a program that counts the number of distinct routes Sang-geun can take to work.
Input
The first line contains two integers and . ()
Output
Print the number of routes Sang-geun can take to work, modulo .
Hint
After turning at an intersection, a car must go straight for at least two blocks before it can turn again; equivalently, it can never turn at two consecutive intersections. For example, when and there are exactly valid routes.