Ensure that you are logged in and have the required permissions to access the test.

The Grid

3.6

27 votes
Problem

Given a square binary grid, you are to find the number of ways to reach the bottom-right corner from the top-left corner of the grid. The rules for the same are follows:

  1. You can travel only on grid positions marked by '0'.
  2. You can travel in horizontal or vertical directions only.
  3. You are not allowed to travel a grid position more than once during one path.

Input:
First line is an integer N ( N <= 100), which is the size of the grid. N lines follow, each containing N space separated numbers which are either '0' or '1'.

Output:
Print a single line which is the answer to the given puzzle.

Sample Input
9
0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0
Sample Output
8512
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?