In WW2, allies have placed their mines on the ground which can be considered as a gird of size N*M. Rows are numbered by integers from 1 to N and columns are numbered by integers from 1 to M. Each...


Comp science


In WW2, allies have placed their mines on the ground which can be considered<br>as a gird of size N*M. Rows are numbered by integers from 1 to N and columns<br>are numbered by integers from 1 to M. Each cell (i,j) has a mine in it if (i+j) is<br>divisible by 2. All the other cells are empty.<br>Two cells are neighbours if they share a boundary or a corner. Your aim is to<br>move from the first row to the last row using some special rules that the<br>automatic mine placing system follows. The mines won't blow if the following<br>rules are followed:<br>• If your current row number is odd, from a 'mined' cell (i.e. cell having a<br>mine in it) you can move only to a neighbouring 'mined' cells in the next<br>row, and similarly, from a 'not mined'(i.e. an empty cell) cell you can<br>only move to a neighbouring 'not mined' cell in the next row.<br>• If your current row number is even, you can move to any neighbouring<br>cell in the next row, irrespective of the mining.<br>You have to find the number of ways to reach row number N starting from row<br>number 1, modulo 10°+7. Two ways are different, if there is at least one<br>different cell on the paths. Find a pythonic approach for the solution and<br>develop a optimized python code. Sample inputs outputs are listed below:<br>Input:<br>1<br>25<br>Output:<br>8<br>

Extracted text: In WW2, allies have placed their mines on the ground which can be considered as a gird of size N*M. Rows are numbered by integers from 1 to N and columns are numbered by integers from 1 to M. Each cell (i,j) has a mine in it if (i+j) is divisible by 2. All the other cells are empty. Two cells are neighbours if they share a boundary or a corner. Your aim is to move from the first row to the last row using some special rules that the automatic mine placing system follows. The mines won't blow if the following rules are followed: • If your current row number is odd, from a 'mined' cell (i.e. cell having a mine in it) you can move only to a neighbouring 'mined' cells in the next row, and similarly, from a 'not mined'(i.e. an empty cell) cell you can only move to a neighbouring 'not mined' cell in the next row. • If your current row number is even, you can move to any neighbouring cell in the next row, irrespective of the mining. You have to find the number of ways to reach row number N starting from row number 1, modulo 10°+7. Two ways are different, if there is at least one different cell on the paths. Find a pythonic approach for the solution and develop a optimized python code. Sample inputs outputs are listed below: Input: 1 25 Output: 8

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here