954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Depth-First Search and Graph

Hi there,

So I'm given a programming problem for a class, and here's what's given:

An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from the upper left corner to the lower right corner of the board. The integer in any one square dictates how large a step away from that location must be. If the step size would advance travel off the game board, then a step in that particular direction is forbidden. All steps must be either to the right or toward the bottom.

Consider the 4 x 4 board shown in Figure 1. Figure 2 shows the three paths from the start (upper left) to the target (lower right), with the irrelevant numbers in each removed.

Figure 1
2 3 3 1
1 2 1 3
1 2 3 1
3 1 1 0
---------------
2 3


1 0
Figure 2
2

1 2 1
0
---------------
2

1
3 0
------------------------------------------
I'm supposed to output how many good paths there are. So my question is, how would you suggest I approach this problem? Thanks for the help!

dark_sider_1
Newbie Poster
24 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Questions that you should be asking yourself...
1. How do I want to store (hold) the grid?
2. How do I generate the grid (random or from a file)?
3. How do I traverse the grid?
4. What do I want my output to look like?
5. What do I have to keep track of, along the way?

This should get you started. Good luck!

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: