Computer Science, asked by shobibalaji26, 25 days ago

It has been a harsh summer for Ants. They have abandoned their homes and reached a new and strange city, which is divided into a number of small squared shape colonies. The head of the Ants takes decisions for the whole community, and the other senior ants have requested him that they are ready to set up in different colonies but all colonies should be within reach from any other colony. Formally, if you consider the city as a 2 dimensional table with m rows and n columns you need to find number of possible ways to set up colonies such that: There is minimum of 1 colony. Colonies should be connected and every colony should be reachable from any other colony. Ants cannot move on diagonals.​

Answers

Answered by pasupuletir259
3

Answer:

It has been a harsh summer for Ants. They have abandoned their homes and reached a new and strange city, which is divided into a number of small squared shape colonies. The head of the Ants takes decisions for the whole community, and the other senior ants have requested him that they are ready to set up in different colonies but all colonies should be within reach from any other colony. Formally, if you consider the city as a 2 dimensional table with m rows and n columns you need to find number of possible ways to set up colonies such that: There is minimum of 1 colony. Colonies should be connected and every colony should be reachable from any other colony. Ants cannot move on diagonals.

Explanation:

It has been a harsh summer for Ants. They have abandoned their homes and reached a new and strange city, which is divided into a number of small squared shape colonies. The head of the Ants takes decisions for the whole community, and the other senior ants have requested him that they are ready to set up in different colonies but all colonies should be within reach from any other colony. Formally, if you consider the city as a 2 dimensional table with m rows and n columns you need to find number of possible ways to set up colonies such that: There is minimum of 1 colony. Colonies should be connected and every colony should be reachable from any other colony. Ants cannot move on diagonals.

Answered by ZareenaTabassum
3

The Answer is:

  • To get to cell (m.n), first get to cell (m-1,n) or cell (m,n-1) and then take one step down or to the right to get to cell (m.n) (m,n). We attempt to develop a bottom-up dynamic programming solution after convincing ourselves that this problem fulfils the optimal sub-structure and overlapping subproblems criteria.

  • We must first determine the states on which the solution will be dependent. What are the variables on which my answer is dependent on determining the number of ways to reach a position? To uniquely identify a position, we require the row and column numbers. As a result, let NumWays(m,n) be the number of ways to get to position (m,n).
  • As previously stated, the number of ways to reach cell (m,n) is equal to the sum of the number of ways to reach (m-1,n) and the number of ways to reach (m,n-1).
  • All you have to do now is take care of the base cases, and the recurrence relation will do the rest.
  • Each cell in the topmost row can only be accessed once, from the left cell. The same is true for the leftmost column.

SPJ2

Similar questions