Prison Break
Practice
3.8 (37 votes)
Algorithms
Approved
Backtracking
Depth first search
Easy
Graphs
Open
Recursion
Problem
79% Success 7315 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Alfie was a prisoner in mythland. Though Alfie was a witty and intelligent guy.He was confident of escaping prison.After few days of observation,He figured out that the prison consists of (\(N × N\)) cells.i.e The shape of prison was (\(N × N\)) matrix. Few of the cells of the prison contained motion detectors.So Alfie planned that while escaping the prison he will avoid those cells containing motion detectors.Yet before executing his plan,Alfie wants to know the total number of unique possible paths which he can take to escape the prison.Initially Alfie is in cell
(\(1,1\)) while the exit of the cell (\(N,N\)).

note:->Alfie can move in all four direction{ if his current location is (\(X,Y\)), he can move to either
(\(X+1,Y\)), (\(X-1,Y\)), (\(X,Y+1\)), (\(X,Y-1\)) }. If the first cell (\(1,1\)) and the last cell(\(N,N\)) contain motion detectors,then Alfie can't break out of the prison.

INPUT:

The first line contain number of test cases "T".T test cases follow.The first line of each test case contains an integer "N",(i.e the size of the (\(N × N\)) matrix).The next n lines contain N space separated values either 0 or 1."1" represents a cell containing motion detectors.

OUTPUT:

output total number of unique possible paths which he can take to escape the prison.

Constraint:

\(1 \le T \le 20\)

\(1 \le N \le 20\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
AlgorithmsDepth First SearchEasyGraphsTrees
Points:20
3 votes
Tags:
AlgorithmsDepth First SearchGraphs
Points:20
18 votes
Tags:
AlgorithmsDepth First SearchGraphs