luogu#P3848. [TJOI2007] 跳棋
[TJOI2007] 跳棋
Background
This problem may be flawed. The current testdata are randomly generated for , and both the testdata and the editorials are for reference only.
On an board filled with 0s and 1s, as shown in Figure (a) (with ), for convenience, the 0s are labeled with letters, as shown in Figure (b).

Problem Description
Rules of the game:
(1) Starting from some 0-cell, you can jump in one of the four directions (up, down, left, right), consecutively over several (at least one) 1-cells, and land on the next 0-cell. In Figure (b), starting from A, you can jump to B or to E, but not directly to K. After jumping to B, you can continue to F; after jumping to E, you can continue to F or K. Continue until no further jump is possible.
(2) Each 0-cell can be visited at most once. The given starting cell cannot be visited again, nor can it be jumped over.
The jump distance equals the number of 1-cells jumped over plus 1. For example, from A to B the distance is 3; from B to F the distance is 2.
Problem: Given the board and the starting point, what is the maximum total jump distance?
In Figure (b), starting from A, there are multiple possible routes. One of them is: A - B - F - L - K - E (possibly not unique) 3 2 3 3 3 Its total distance is 14.
Input Format
The first line contains three integers: (1 ≤ ≤ 100), , (coordinates of the starting point; in Figure (b), the coordinates of A are 1, 3).
Then follow lines, each containing numbers (0 or 1), separated by a single space.
Output Format
Output a single integer: the maximum total jump distance (output 0 if no jump is possible).
4 3 2
1 0 1 0
1 1 1 1
0 0 1 0
1 1 0 1
6
Hint
:A new hack testdata has been added.
Translated by ChatGPT 5