Game Addiction
InterviewTime limit1sMemory limit1024 MB
Count shortest lattice paths between two diagonal points while staying inside the unflooded region y <= x.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Gangsan is a serious game addict, so he goes to the PC bang every day no matter the weather.
Recent heavy rain flooded some areas, and he cannot move into flooded areas. Even so, Gangsan must go to the PC bang every single day for the attendance event.
Gangsan moves to the PC bang only in the up, down, left, and right directions, and each move has distance 1. He also wants to play his game quickly, so he moves from home to the PC bang along a shortest path.
Given the coordinates of Gangsan's home and the PC bang , and given that a point on the coordinate plane is flooded when , find the number of paths Gangsan can take to reach the PC bang while avoiding flooded areas.
If the PC bang has the same coordinates as his home, the number of paths is 1.
Input
The first line gives two integers and (), the coordinates of the home and the PC bang , in that order.
Output
Print the number of paths from home to the PC bang.