PLEASE WRITE THE JAVA CODE TO SOLVE THIS THANKS YOU Given a triangle of positive
ID: 3538646 • Letter: P
Question
PLEASE WRITE THE JAVA CODE TO SOLVE THIS THANKS YOU
Given a triangle of positive integers, we want to find a largest possible sum along a path from top row to bottom row. A path can go down either directly south or directly south-east (Note, you can NEVER go EAST, WEST, or NORTH etc). For example, m the triangle the path 1 rightarrow 3 rightarrow 7 rightarrow 2 rightarrow 13 is a legal path with sum 26. This path is "best" because 26 is the largest such sum. Generally, suppose that the triangle is stored in an array A[l..n,1..n] with the relevant entries being on the diagonal and below. For 1 r n and 1 c r let B[r,c] be the sum along the best path that ends in row r and column c of the matrix A. Example: B[1,1] = 1, B[2,1] = 3, B[2,2] = 4 There are several sets of triangle data. For each set of triangle data, the first number is the number of rows (n) in the triangle. This is followed by n rows of data. Row i has i cols of data. All data is integer type. There are two lines of data for EACH set of triangle data. The first line states "Max is ???" where ??? is the largest path sum. The second line shows the path. (See the Sample). INPUT 2 18 430 302 6 102 76 76 268 153 185 492 480 112 405 286 436 126 25 391 390 32 399 76 29 174 OUTPUT Max is 448 18-->430 Max is 1773 102-->76-->268-->492-->436-->399Explanation / Answer
import java.util.Scanner; public class Main{ public static void main(String []args){ int linescount,i,j; Scanner in = new Scanner(System.in); while(in.hasNextLine()) { linescount = in.nextInt(); int[][] table = new int[linescount][linescount]; for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.