Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions PrintMazePathWithJump.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

// KHUD SE

import java.io.*;
import java.util.*;

public class Main {

public static void main(String[] args) throws Exception {
Scanner scn = new Scanner (System.in);
int n = scn.nextInt();
int m = scn.nextInt();
printMazePaths(1, 1, n, m, "");

}

// sr - source row
// sc - source column
// dr - destination row
// dc - destination column
public static void printMazePaths(int sr, int sc, int dr, int dc, String psf) {
// if(sc>dc || sr>dr){
// return;
// }

if(sc==dc && sr==dr){
System.out.println(psf);
return;
}


for(int i=1; i<=dc-sc; i++){
printMazePaths(sr, sc+i, dr, dc, psf+ "h"+i);
}
for(int j=1; j<=dr-sr; j++){
printMazePaths(sr+j, sc, dr, dc, psf+ "v"+j);
}
for(int k=1; k<=dr-sr && k<=dc-sc; k++){
printMazePaths(sr+k, sc+k, dr, dc, psf + "d"+k);
}


}

}