#P15567. [COCI 2025/2026 #5] 五步 / Pet

    ID: 17431 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>动态规划 DPO2优化组合数学COCI(克罗地亚)2026bitset

[COCI 2025/2026 #5] 五步 / Pet

Background

The full score for this problem is 110110.

Problem Description

The frog Maša is playing in a lake consisting of nn rows and mm columns. Each cell of the lake is either the character 00 (meaning water) or 11 (meaning a lily pad).

Maša can only stand on lily pads. From one lily pad, she can jump to any other lily pad in the same row or the same column. However, her jumps must alternate: if the previous jump changed the column, then the next jump must change the row. If the previous jump changed the row, then the next jump must change the column.

Each time Maša jumps away from her current lily pad, that lily pad sinks and cannot be jumped onto again.

Maša wants to visit a total of 55 lily pads in one path (including the starting pad). She may choose any lily pad as the starting point. Compute how many paths satisfy the conditions. Two paths are considered different if the coordinates of the lily pads at any of positions 1∼51 \sim 5 are different.

Input Format

The first line contains two natural numbers n,mn, m (1≤n,m≤20001 \le n, m \le 2000).

The next nn lines each contain mm characters (00 or 11), describing the lake grid.

Output Format

Output a single integer, the number of paths that satisfy the conditions.

2 3
111
110
4
4 4
1111
1111
1111
1111
2304
2 5
11110
01111
48

Hint

Sample Explanation

Explanation for Sample #1:

The 44 paths are:

  • (1,1)→(2,1)→(2,2)→(1,2)→(1,3)(1,1)\to(2,1)\to(2,2)\to(1,2)\to(1,3)
  • (1,2)→(2,2)→(2,1)→(1,1)→(1,3)(1,2)\to(2,2)\to(2,1)\to(1,1)\to(1,3)
  • (1,3)→(1,2)→(2,2)→(2,1)→(1,1)(1,3)\to(1,2)\to(2,2)\to(2,1)\to(1,1)
  • (1,3)→(1,1)→(2,1)→(2,2)→(1,2)(1,3)\to(1,1)\to(2,1)\to(2,2)\to(1,2)

Subtasks

Subtask Score Limit
11 88 n,m≤4n, m \le 4
22 2727 n,m≤10n, m \le 10
33 5858 n,m≤400n, m \le 400
44 1717 No additional constraints

Translated by ChatGPT 5