#P1002. [NOIP 2002 普及组] 过河卒

[NOIP 2002 普及组] 过河卒

Description

On a chessboard, there is a river-crossing pawn at point AA that needs to reach the target point BB. The pawn moves according to the rules: it may move either downward or rightward. There is also an opposing knight at point CC on the board; the knight’s own square and all squares reachable by a single knight move are called the knight’s controlled squares. Therefore, this is called “the knight blocks the river-crossing pawn.”

The board is represented using coordinates: point AA is at (0,0)(0, 0), point BB is at (n,m)(n, m), and the knight’s position is also given.

You are to compute the number of distinct paths by which the pawn can travel from point AA to point BB, assuming the knight’s position is fixed and does not move in response to the pawn’s moves.

Input Format

One line contains four integers, representing the coordinates of point BB and the coordinates of the knight, in order: nn, mm, xx, yy.

Output Format

Output a single integer, the total number of valid paths.

6 6 3 3

6

Hint

For 100%100\% of the data, 1n,m201 \le n, m \le 20, and the knight’s coordinates satisfy 0x,y200 \le x, y \le 20.

[Source]

NOIP 2002 Junior, Problem 4.

Translated by ChatGPT 5