Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

give me cpp code 2. THE PROBABILITY PROBLEM You are given a grid, of N rows, and M columns, with some free cells, and some

image text in transcribed

give me cpp code

2. THE PROBABILITY PROBLEM You are given a grid, of N rows, and M columns, with some free cells, and some blocked cells. You can only step on empty cells, and you can never step on a blocked cell. Also, you are not allowed to go out from the grid. From the current empty cell, you may only go to a cell, which is located either Down, or right to the current cell. More formally, from an empty cell (x,y) you may go only to either (x+1,y), or (x,y+1), and to whichever cell you decide to go, in should be empty. Currently, you are at the top left cell of the grid, i.e at cell (1,1), and you need to go to the bottom right cell (nm). Some cells of the grid are special. These are the cells, which are currently empty, but if blocked, then no path will exist from cell (1,1) to (nm). You need to tell : What is the probability, that if you pick an empty cell from the grid, then that empty cell is special too. Since the probability can be expressed as a fraction P/Q, where P and Q are mutually coprime, you should express this as p+mod_inverse(Q). Where mod_inverse(Q) is the multiplicative modulo inverse of Q in mod 1,000,000,007. INPUT FORMAT - The first line of input contains two space separated integers, N and M, denoting the number of rows, and columns in the grid. Then, N lines follow, where each line represents a single string, containing M characters, which is the i'th row of the grid. OUTPUT FORMAT - Print a single line, containing a single integer, the required probability, CONSTRAINTS - 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

5. Structure your speech to make it easy to listen to

Answered: 1 week ago

Question

1. Describe the goals of informative speaking

Answered: 1 week ago