NOIP '18 P5 - Grid-filling Game

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

There is an n×m grid. A valid path P from the upper left corner to the bottom right corner is a path such that movements are only allowed in the right or in the down directions, and we may use a string w(P) to represent the path in the way that if in the i-th step we move right then the i-th character of w(P) is R while if in the i-th step we move down then the i-th character of w(P) is D. The length of w(P) shall be n+m2.

Now we are going to fill the grids with number 0 or 1. For a valid path P, if we write down the numbers in the grids on the path (including the start and the end, in the order we visit the grids), we get a string of length n+m1, s(P). Compute the number of ways to fill the grids with 0 or 1, modulo 109+7, such that for any two valid paths P1,P2, if w(P1)>w(P2) in the lexicographic order, then s(P1)s(P2) in the lexicographic order.

Input Specification

The input consists of one line with two integers n,m separated by a space denoting the size of the grid. n denotes the number of rows in the grid, while m denotes the number of columns in the grid.

Output Specification

The output consists of one line containing an integer denoting the number of valid ways to fill the grid with 0 and 1 subject to the constraint mentioned in the statement, modulo 109+7.

Sample Input 1

Copy
2 2

Sample Output 1

Copy
12

Explanation

The two possible paths from the upper-left corner to the bottom-right corner have w(P1)=RD and w(P2)=DR. As a result, the invalid ways to fill the grid with 0 and 1 are exactly the ways to fill the grids such that s(P1)>s(P2), which happens if and only if when the upper-right corner is 1 and the bottom-left corner is 0. Therefore, the answer in this case shall be 2422=12.

Sample Input 2

Copy
3 3

Sample Output 2

Copy
112

Sample Input 3

Copy
5 5

Sample Output 3

Copy
7136

Constraints

Test Case n m
1-4 3 3
5-10 2 106
11-13 3 106
14-16 8 8
17-20 8 106

Comments

There are no comments at the moment.