From 1d5f698e6ed31a0d4a7cc41bfb0720aedf9e38b8 Mon Sep 17 00:00:00 2001 From: Ahsan Alam <91831193+AhsanAlam48@users.noreply.github.com> Date: Sat, 9 Oct 2021 03:13:04 +0530 Subject: [PATCH] Print Maze Path With Jump in java file Print all possible maze paths with a jump as well as one step in a row or column in java code --- PrintMazePathWithJump.java | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 PrintMazePathWithJump.java diff --git a/PrintMazePathWithJump.java b/PrintMazePathWithJump.java new file mode 100644 index 00000000..97ad1aab --- /dev/null +++ b/PrintMazePathWithJump.java @@ -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); + } + + + } + +}