Advertisement
steverobinson

Puzzle: Grid Traversal

Mar 23rd, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. Traverse through the board
  2.  
  3. Problem code: TRAVERSE
  4. ---------------------------------
  5.  
  6. An n x n game board is filled with integers, one positive integer per square. The objective is to travel along any legitimate path from the upper left corner to the lower right corner of the board.
  7.  
  8. Rules
  9.  
  10. 1.The number in any one square describes how far a step away from that location must be.
  11. 2.If the step size moves out of the game board, then that step is not allowed.
  12. 3.All steps must be either to the right or towards the bottom.
  13.  
  14. Note that a 0 is a dead end which prevents any further progress.
  15.  
  16. Consider the 4 x 4 board shown in Figure 1, where the solid circle identifies the start position and the dashed circle identifies the target. Figure 2 shows the three paths from the start to the target, with the irrelevant numbers in each removed.
  17.  
  18. http://lulzimg.com/view/0bac00.jpg
  19.  
  20. Input
  21.  
  22. The first line contains the value of n followed by a nxn matrix depicting the board configuration.
  23.  
  24. Output
  25.  
  26. The output consists of a single integer, which is the number of paths from the upper left corner to the lower right corner.
  27.  
  28. Example
  29.  
  30. Input:
  31.  
  32. 4
  33. 2331
  34. 1213
  35. 1231
  36. 3110
  37.  
  38. Output:
  39. 3
  40.  
  41. Input:
  42.  
  43. 4
  44. 3332
  45. 1213
  46. 1232
  47. 2120
  48.  
  49. Output:
  50.  
  51. 0
  52.  
  53. Input:
  54.  
  55. 5
  56. 11101
  57. 01111
  58. 11111
  59. 11101
  60. 11101
  61.  
  62. Output:
  63. 7
  64.  
  65. <<Solution done. Contact steve_robinson@live.com>> footyntech.wordpress.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement