Problem Statement:
Count all the possible paths in the given maze.
Note: Only right and bottom moves allowed.
Solution:
Run Source Code
We would using recursion to count the possible pats, as (N-1,N-1) is reached count is incremented each time.
Below is logic implemented.
Please comment and post your suggestions.
Happy Coding !! :)
Count all the possible paths in the given maze.
Note: Only right and bottom moves allowed.
Solution:
Run Source Code
We would using recursion to count the possible pats, as (N-1,N-1) is reached count is incremented each time.
Below is logic implemented.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /** * Find count of possible paths in the maze * @author PRATEEK */ public class CountPaths { private static int rowLen, colLen, count; public static void paths(int[][] maze, int row, int col) { if (row == rowLen && col == colLen) { count++; return; } /*// move left if (col > 0 && maze[row][col - 1] == 1) paths(maze, row, col - 1);*/ // move right if (col < colLen && maze[row][col + 1] == 1) paths(maze, row, col + 1); /*// move up if (row > 0 && maze[row - 1][col] == 1) paths(maze, row - 1, col);*/ // move down if (row < rowLen && maze[row + 1][col] == 1) paths(maze, row + 1, col); } public static void main(String[] args) { int[][] maze = { {1, 1, 0, 0, 1, 1 }, {1, 1, 1, 1, 0, 0 }, {1, 0, 0, 0, 1, 0 }, {1, 1, 1, 1, 0, 0 }, {1, 0, 1, 0, 0, 0 }, {1, 1, 1, 1, 1, 1 } }; rowLen = maze.length-1; colLen = maze[0].length-1; paths(maze,0,0); System.out.println("Number of Paths: "+count); } } |
Please comment and post your suggestions.
Happy Coding !! :)
Is the audience still comprised of decision makers. If you currently have
ReplyDeletea trade exhibition booth designed, get it ready for a full analysis.
Visit your customers' Facebook pages and personally invite the crooks to
stop by and visit your display displays and banner stands.
my weblog - portable display system ()
Is the viewers still made up of decision makers.
ReplyDeleteBut, reaching out to the target market, instilling interest one of them, was difficult since there was no
definitive means of promoting the brand or business via
brochures. Visit your customers' Facebook pages and personally
invite these phones stop by and visit your trade show displays and
banner stands.
my weblog :: discount portable booth displays
Some birds, by way of example will embark on singing displays that mirror
ReplyDeletethe motions in the grass display like the Cutthroat finch.
If your unit is not modular, contact the company before you make any structural changes.
If the consumer had to get a display, it will either should be a
one-size-fits-all model, or they may have to purchase
several different sized exhibits.
Also visit my site; buy display panels
Is the crowd still consists of decision makers. If your unit is just not modular, contact the business before you make
ReplyDeleteany structural changes. Three popular raffle drum trends you have probably affecting action are fabricated from either steel,
clear acrylic, or some other form of plastic known as PETG.
Here is my weblog :: cheap convention displays
Hey there! I know this is kinda off topic but I wass wondering which
ReplyDeleteblog platform are you using for this website?
I'm getting sick andd tired off Wordpress because I've hhad
problems with hackers and I'm looking at options for another platform.
I would be awesome if you could point me in the direction of a good platform.
Also visit my web site - Las Vegas Dryer Parts
Great blog! Do you have any suggestions for aspiring writers?
ReplyDeleteI'm hoping to start my own website soon but I'm a little
lost on everything. Would you recommend starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm completely overwhelmed ..
Any recommendations? Appreciate it!
Check out my website price private jet
Great site. Plenty of helpful info here. I'm sending
ReplyDeleteit to several friends ans additionally sharing in delicious.
And of course, thanks for your sweat!
Feel free to visit my webpage: hiring private jet
you are actually a good webmaster. The site loading pace is incredible.
ReplyDeleteIt sort of feels that you're doing any unique trick.
Furthermore, The contents are masterwork. you
have done a excellent task in this topic!
My web site ... seo company offer
Truly no matter if someone doesn't be aware of after that its up to other users that they will help, so here it happens.
ReplyDeleteMy web page: rent a private jet cost
lebron shoes
ReplyDeletekobe 11
huarache shoes
curry shoes
hermes bag
cheap jordans
vapormax
moncler outlet
vans shoes
kate spade outlet