[Solution] Red Green Grids CodeChef Solution
Problem
There is an empty grid (all cells are colored white) of rows and columns.
Chef can fill each cell with either RED
or GREEN
color.
Chef defines a valid path as a path of cells starting from and ending at , where, Chef moves either right
or down
by cell each time.
For a particular grid, Chef defines the score of the grid as the number of valid paths containing equal number of RED
and GREEN
cells.
Find the sum of scores of all possible colored grids containing rows and columns.
Since the answer can be large, output it modulo .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two integers and - denoting the dimensions of the grid.
Output Format
For each test case, output the sum of scores of all possible colored grids containing rows and columns, modulo .
Explanation:
Test case : There are possible coloured grids of size . In the first grid, the one and only cell is colored RED
. In the second grid, the one and only cell is colored GREEN
. Neither of the grids have a valid path with equal number of red and green cells. Thus, score of each grid is .
Test case : There are possible coloured grids of the given dimension:
For grids and , the scores are as there are no valid paths with equal red and green cells. Grids and have score each. The valid path with equal red and green cells is in both the grids.
Thus, the sum of scores of all possible coloured grids is .
No comments:
Post a Comment