本地题面缓存已迁移,解析内容待补充。
OJ: noi_openjudge
题目 ID: ch0206-90
难度:未知
标签:python
日期: 2026-07-30 23:01
题意
完整题面见同目录的 problem.md。
思路
代码
Python代码
python
import sys
from functools import cache
sys.setrecursionlimit(20_000)
row_count, column_count = map(int, input().split())
heights = [list(map(int, input().split())) for _ in range(row_count)]
@cache
def longest_from(row: int, column: int) -> int:
best = 1
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
next_row, next_column = row + dr, column + dc
if (
0 <= next_row < row_count
and 0 <= next_column < column_count
and heights[next_row][next_column] < heights[row][column]
):
best = max(best, 1 + longest_from(next_row, next_column))
return best
print(max(longest_from(row, column) for row in range(row_count) for column in range(column_count)))