Path with the smallest sum

Source: Internet
Author: User

Path with the smallest sum

Question:

Given the m * n matrix, each position is a non-negative integer. Starting from the upper left corner, you can only go to the right and bottom at a time and go to the lower right corner, but only once to find the path with the smallest sum.

Ideas:

Because it takes only one time, it is relatively simple, dp [0, 0] = a [0, 0], and dp [x, y] = min (dp [X-1, y] + a [x, y], dp [x, Y-1] + a [x, y]).

# Include

 
  
# Include

  
   
# Define min (x, y) (x) <(y )? (X) :( y) int getMinSumOfArray (int a [] [5], int row, int col) {int dp [100] [100]; int I; int j; dp [0] [0] = a [0] [0]; for (I = 1; I

   

    

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.