Given numbers in form of an Inverted triangle. By starting at the bottom of the triangle and moving to adjacent numbers on the row above, find the maximum total from bottom to top.
Input : 1 5 3 4 8 1 Output : 14 Input : 8 5 9 3 2 4 6 7 4 3 Output : 23
Approach : In the previous article we saw an approach of the problem where the triangle is non-inverted.
Here also we will use the same approach to find the solution of the problem as discussed in previous article.
If we should left shift every element and put 0 at each empty position to make it a regular matrix, then our problem looks like minimum cost path.
So, after converting our input triangle elements into a regular matrix we should apply the dynamic programming concept to find the maximum path sum.
Applying, DP in bottom-up manner we should solve our problem as:
8 5 9 3 2 4 6 7 4 3 Step 1 : 8 5 9 3 2 4 6 0 7 4 0 0 3 0 0 0 Step 2 : 8 5 9 3 2 4 6 0 10 7 0 0 Step 3 : 8 5 9 3 12 14 13 0 Step 4: 20 19 23 16 Output : 23
Below is the implementation of the above approach:
- Maximum path sum in a triangle.
- Maximum sum of a path in a Right Number Triangle
- Minimum Sum Path in a Triangle
- Minimum length of the shortest path of a triangle
- Maximum Perimeter Triangle from array
- Path with maximum average value
- Maximum height when coins are arranged in a triangle
- Minimum and maximum possible length of the third side of a triangle
- Maximum area of triangle having different vertex colors
- Maximum sum path in a matrix from top to bottom
- Maximum number of squares that can fit in a right angle isosceles triangle
- Maximum number of 2x2 squares that can be fit inside a right isosceles triangle
- Maximum decimal value path in a binary matrix
- Maximum sum path in a matrix from top to bottom and back
- Maximum path sum for each position with jumps under divisibility condition
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.