#P3848. [TJOI2007] 跳棋

    ID: 2764 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>搜索2007各省省选递归深度优先搜索,DFS天津

[TJOI2007] 跳棋

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: nn (1 ≤ nn ≤ 100), xx, yy (coordinates of the starting point; in Figure (b), the coordinates of A are 1, 3).

Then follow nn lines, each containing nn 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

upd 2022.7.27\text{upd 2022.7.27}:A new hack testdata has been added.

Translated by ChatGPT 5