Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to analyze the minimum path and sum in big data

Shulou Source: shulou.com Published: 2022-06-01 16:05:04 09月26日 Update

How to analyze the minimum path sum in big data? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

one

Topic description

Given a m x n grid that contains non-negative integers, find a path from the upper left to the lower right so that the sum of the numbers on the path is minimized, and you can only move down or right one step at a time.

two

Answer to the question

Idea: dynamic programming in the LeetCode: longest reply substring we introduce the meaning of dynamic programming, this time we will not repeat it, but go directly to the logic.

The first step is to find the intermediate state: where the intermediate state dp [I] [j] represents the sum of the smallest paths from the upper left corner to the elements in the matrix (iGrainj).

The second step is to determine the state transition: according to the route transition relationship, dp [I] [j] = dp [0] [jmur1] + grid [I] [j] can only be reached from above, so dp [I] [j] = DP [I-1] [0] + grid [I] [j], other times Then there is dp [I] [j] = min (DP [I-1] [j], dp [I] [jmur1]) + grid [I] [j].

Class Solution: def minPathSum (self Grid: list [return])-> int: if not grid: return 0m = len (grid) n = len (grid [0]) dp = [[0] * n for i in range (m)] for i in range (m): for j in range (n): if j = = 0 and I = = 0: dp [I] [j] = grid [0] [0] elif j = = 0 and iTunes 0: dp [I] [j] = DP [I-1] [0] + grid [I] [j] elif jacks 0 and iTunes 0: dp [I] [j] = dp [0] [jmur1] + grid [ I] [j] else: dp [I] [j] = min (DP [I-1] [j]) Dp [I] [jmur1]) + grid [I] [j] return dp [- 1] [- 1] the answers to how to analyze the shortest paths and questions in big data are shared here. I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.

Tags: Path minimum analysis state question data dynamic upper left corner more help planning solution easy longest easy above element content meaning palindrome Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL MariaDB vpn Shulou Tech Info