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

Can any one help to writ it in Java? Can any one help to writ it in Java? YNAMIC

ID: 3910958 • Letter: C

Question

Can any one help to writ it in Java?

Can any one help to writ it in Java?

YNAMIC PROGRAMMING 17. /5) Consider the same situation as the previous problem. We have a city whose streets are defined by an x y grid. We are interested in walking from the upper left-hand corner of the grid to the lower right-hand corner. We are given an X × Y matrix BAD, where BAD -"yes" if and only if the intersection between streets i and j is somewhere we want to avoid. If there were no bad neighborhoods to contend with, the shortest path across the grid would have length (X - 1) (Y-1) blocks, and indeed there would be many such paths across the grid. Each path would consist of only rightward and downward moves. Give an algorithm that takes the array BAD and returns the number of safe paths of length X +Y- 2. For full credit, your algorithm must run in o(xY).

Explanation / Answer

import java.io.*;

import java.util.Scanner;

class PathFinder {

public static void main (String[] args) {

Scanner sc = new Scanner(System.in);

int x=0,y=0;

System.out.println("Enter value of X");

x=sc.nextInt();

System.out.println("Enter value of Y");

y=sc.nextInt();

int path[][] = new int[x][y];

System.out.println("Enter " + x*y +" elements ");

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

for(int j=0; j<y; j++){

String temp=sc.next();

if(temp.equalsIgnoreCase("yes")){

path[i][j]=0;

}else if(i==0&&j==0){

path[i][j]=1;

}else if(i==0){

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

}else if(j==0){

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

}else{

path[i][j]=path[i-1][j]+path[i][j-1];

}

}

}

System.out.println("No. of possible paths = "+ path[x-1][y-1]);

}

}

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