Number triangle opening

Source: Internet
Author: User

A few of my colleagues discussed a topic a few days ago as an example of dynamic planning. I think it is quite classic. Record it.

The general consistency is as follows:

A digital triangle, for example, has multiple paths from the top to the bottom. For each path, add the numbers in the path to get the maximum path of a sum and sum, is an optimal path. Find the optimal path.

5

4 5

4 5 9

9 8 4 8

9 0 7 4 8

0 9 2 4 5 8

Requirements:

Each step of the path can only go from a number to the number on the left or right of the next layer and closest to it.

Input: the first line is an integer N (1 <n <100). The number of rows in the triangle is displayed, and the number triangle is displayed after driving. The number ranges from 0 ~ In the range of 100.

Output: Maximum Sum.

 

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.