Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAM Modify the memoizedCutRod method to keep track of the rod length th

ID: 647312 • Letter: J

Question

JAVA PROGRAM

Modify the memoizedCutRod method to keep track of the rod length that generates the
optimal solution for each of the rod lengths.
? Add a column to the output table to show the optimal rod cut results ? the lengths of the
rods (after the cuts) that yield the optimal revenue values
? The output table should now have these columns with headers:
Length , Rev CR, Num Calls CR, Rev MCR, Num Calls MCR, Cut Pieces
The output from running the program should display on the screen
as follows:

JAVA PROGRAM Modify the memoizedCutRod method to keep track of the rod length that generates the optimal solution for each of the rod lengths. ac Add a column to the output table to show the optimal rod cut results a?? the lengths of the rods (after the cuts) that yield the optimal revenue values ac The output table should now have these columns with headers: Length , Rev CR, Num Calls CR, Rev MCR, Num Calls MCR, Cut Pieces The output from running the program should display on the screen as follows:

Explanation / Answer

import java.io.*;

import java.util.*;

public class MemorizedCutRod

{

      

       public static double cutRod(double[] p, int n)

       {

              if(n==0) return 0;

             

              double q=-1000;

              for(int i=0;i<n;i++)

              {

                     q=Math.max(q,p[i]+cutRod(p,n-i-1));

                     System.out.println(q);

              }

              return q;

       }

      

       public static void main(String[] args)

       {

              double[] p={1,5,8,9,10,17,17,20,24,30};

              double val = cutRod(p,10);

              System.out.println(val);

       }

}