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

These are my three input text files. Input A 6 10 50 5 12 27 23 16 38 44 30 15 3

ID: 3743108 • Letter: T

Question

These are my three input text files.

Input A

6
10 50 5 12 27
     23 16 38 44
          30 15 33
             33 43
                  12

Input B

6
15 20 34 24 1
     23 35 23 15
          35 24 33
               12 30
                    44

Input C

6
1 25 35 23 50
      1 33 44 20
           1 34 44
                1 24
                     1

el or annu epartme the Flint River. Canoes are available for r at post 0 and ends at post n -1 However, individuals do not have to keep the same canoe for the entire trip; one can stop at any post, drop off the canoe used to reach that post, and rent another canoe. One may make as many stops on the river as desired. All canoe rental costs are positive integers. There is no added charge for exchanging canoes at a post. Travel down the river is one-way (downstream) For all pairs (a, b) with a

Explanation / Answer

CODE:

CanoeAndPosts.java

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class CanoeAndPosts {

public static int Canoe(int A[][]) {

/*the solutions matrix*/

int[][] T = new int[A.length][A[0].length];

/*Let the first row of T be the first row of A[][]*/

for(int i = 0; i < A.length; i++) {

T[0][i] = A[0][i];

}

/*Dynamically incur solution into T*/

for(int i = 1; i < A.length; i++) {

for(int j = 0; j < A.length; j++) {

if (j <= i) {

T[i][j] = T[i - 1][j];

} else {

T[i][j] = Math.min(T[i - 1][j], T[i - 1][i] + A[i][j]);

}

}

}

return T[T.length - 1][T.length - 1];

}

public static void main (String[] args) {

int min = 0;

try {

Scanner sc = new Scanner(System.in);

System.out.println("Enter the input file name with path:");

String fileName = sc.nextLine();

BufferedReader bufReader = new BufferedReader(new FileReader(fileName));

String fileRead = bufReader.readLine();

int n = Integer.parseInt(fileRead);

int arrayCanoe[][] = new int[n][n];

String[] fileRead2 = new String[n];

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

fileRead2[i] = bufReader.readLine();

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

try {

String[] array = fileRead2[i].split(" ");

//for(int j=0;j<n;j++)

//System.out.println(array[j]);

for(int k=0;k<n;k++) {

if(array[k].equals("-")) {

arrayCanoe[i][k] = 0; }

else {

arrayCanoe[i][k] = Integer.parseInt(array[k]);

}

//System.out.println(arrayCanoe[i][k]);

}

}catch(Exception e) {}

}

min = Canoe(arrayCanoe);

System.out.println("The min cost is :"+min);

sc.close();

bufReader.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

Input.txt File :

4

- 10 15 50

- - 40 20

- - - 35

Sample Output :

Enter the input file name with path: D:/Input.txt The min cost is :30

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote