Submit | All submissions | Best solutions | Back to list |
TRAVERSE - Traverse through the board |
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.
Rules
1. The number in any one square describes how far a step away from that location must be.
2. If the step size moves out of the game board, then that step is not allowed.
3. All steps must be either to the right or towards the bottom.
Note that a 0 is a dead end which prevents any further progress.
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.
Input
The first line contains the value of n followed by a nxn matrix depicting the board configuration.
Output
The output consists of a single integer, which is the number of paths from the upper left corner to the lower right corner.
Example
Input:
4
2331
1213
1231
3110
Output:
3
Input:
4
3332
1213
1232
2120
Output:
0
Input:
5
11101
01111
11111
11101
11101
Output:
7
Added by: | Infinity |
Date: | 2011-03-21 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ADA95 ASM32 ASM64 BASH CLPS CLOJURE LISP sbcl LISP clisp D ERL FSHARP FORTRAN GO ICON ICK LUA NEM NICE OCAML PIKE PRLG-swi SCM guile SCM qobi ST TCL WHITESPACE |
hide comments
|
|||||||
2019-12-03 19:55:43
Image isn't needed, problem description describes it well enough. Just note that newline is not needed in output. |
|||||||
2018-07-15 10:00:03
Don't print new line after output..Costed me 3 WA.What a waste of time.. |
|||||||
2018-06-30 09:36:00
Be carefull with input there are no spaces provided between elements of a row. |
|||||||
2017-12-12 08:35:57
only recursion passes in 0.00s |
|||||||
2015-08-25 12:54:04 PRIBAN91
Terrible output format! Don't print a newline character in output. Should have read the comments first! |
|||||||
2015-07-22 11:24:20
Make sure,, you don't add a newline after printing the answer.. It costed me 2 WA :( |
|||||||
2015-06-14 11:46:18 Piyush Kumar
The image is missing . |
|||||||
2015-06-04 12:10:08 vivek singh rana
either we can move only right,or only down,,only two choices,,,thats why answer of test case 1 is 3 (would have been 6 otherwise). |
|||||||
2014-12-23 10:12:22 Jugal kishor sahu
AC: easy recursion 2 wrong answer due to '\n'........ don't print newline after output...... |
|||||||
2014-09-30 10:38:20 NOVICE
Cakewalk DP>>>!! |