Problem:
The N * n table contains natural numbers. Starting from any location, the numbers in the table can be moved to the four adjacent domains (provided that the numbers in the direction of movement must be smaller than the current number ), move one distance and add one. What is the maximum moving distance?
Analysis:
The problem can be considered as a dynamic programming problem, H [I] [J] = max {H [I-1] [J], H [I + 1] [J], H [I] [J-1], H [I] [J + 1]} + 1, the conditions such as a [I] [J]> A [I-1] [J] are met.
After discussion with gjh, it is found that there is a better way to find the minimum element from the matrix at a time and update the four elements around the minimum element, the update result is max {H [I] [J] + 1, h [I + 1] [J]}, H [I] [J] indicates the longest length of a decimal number string starting from the smallest element.
AlgorithmCode:
Not compiled yet