Question: can anyone edit my code to printout the maximum-profit path in java? The maximum profit is 42. The maximum profit path is: (1,5) (2,4) (3,5)

can anyone edit my code to printout the maximum-profit path in java?

The maximum profit is 42. The maximum profit path is: (1,5) (2,4) (3,5) (4,5) (5,4)

p table

0 0 0 0 0 0 0 0 4 8 2 3 5 0 0 2 7 5 10 2 0 0 3 2 7 7 9 0 0 6 5 7 7 9 0 0 8 7 5 9 8 0

my code.

import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; import java.util.Stack;

public class MPPP1 { public static void computeQ(int[][] q,int[][] p, int[][] d) { int n = p.length; for (int j=1;j above && upperright > upperleft) { d[i][j] = j+1;} else if (above > upperright && above > upperleft) { d[i][j] = j; } else { d[i][j] = j-1; } q[i][j] = p[i][j]+Math.max(upperleft, Math.max(above, upperright)); } } } public static void printPath(int[][] d, int maxcolumn) { Stack s = new Stack(); int n = d.length; int column = maxcolumn; for (int row=n;row>=1;row--) { s.push(column); column = d[row-1][column]; } for (int row=1;row<=n;row++) { s.pop(); System.out.println("("+row+","+column+")"); } } public static void main(String... args) throws IOException {

// Open the file and read each integer one-by-one //System.out.print("if the file path is different, replace the file path in the code: "); //System.out.println(System.getProperty("user.dir")); Scanner scanner = new Scanner(new File("C:\\Users\\qq339\\eclipse-workspace\\test\\src\\test\\ptable.txt")); //Scanner scanner = new Scanner(new File("C:\\ptable.txt")); int[][] q = new int[6][7]; int[][] p = new int[6][7]; int[][] d = new int[6][7]; while (scanner.hasNextInt()) { for (int i=0;i<6;i++) { for (int j=0;j<7;j++) { p[i][j] = scanner.nextInt();}} } /* for (int i=0;i max) { max = q[n][j]; maxcolumn=j; } } System.out.println("The maximum profit that can be earned is "+ max); printPath(d,maxcolumn); /*for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!