Two-dimensional matrix for solving the maximum moving distance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.