luogu#P5023. [NOIP 2018 提高组] 填数游戏

[NOIP 2018 提高组] 填数游戏

Background

NOIP 2018 Senior D2T2.

Problem Description

Xiao D really likes playing games. One day, he was playing a number filling game.

The board of this game is an n×mn \times m rectangular grid. The player needs to fill each cell in the grid with a number (either 00 or 11), and the filling must satisfy some constraints.

We describe these constraints in detail below.

For convenience, we first give some definitions:

  • We use the row and column coordinates of each cell to represent a cell, i.e., (row, column). Note: both row and column coordinates start from 00.

  • A valid path PP: A path is valid if and only if:

    1. The path starts from the top-left cell (0,0)(0,0) of the grid and ends at the bottom-right cell (n1,m1)(n - 1,m - 1);
    2. Along this path, each move can only go from the current cell to the adjacent cell on its right, or from the current cell to the adjacent cell below it.

    For example, in the rectangle below, only two paths are valid: P1P_1: (0,0)(0,1)(1,1)(0,0)\to (0,1)\to (1,1) and P2P_2: (0,0)(1,0)(1,1)(0,0) \to (1,0) \to (1,1).

For a valid path PP, we can represent it with a string w(P)w(P) of length n+m2n + m - 2, which contains only the characters R\texttt R or D\texttt D. The ii-th character records how the ii-th step of path PP moves. R\texttt R means moving to the adjacent cell on the right of the current cell, and D\texttt D means moving to the adjacent cell below the current cell. For example, for path P1P_1 in the figure above, w(P1)=RDw(P_1) = \texttt {RD}; for the other path P2P_2, w(P2)=DRw(P_2) = \texttt {DR}.

Also, if we concatenate, in order, the numbers filled in each cell visited by a valid path PP, we obtain a 0101 string of length n+m1n + m - 1, denoted by s(P)s(P). For example, if we fill 00 in cells (0,0)(0,0) and (1,0)(1,0), and fill 11 in cells (0,1)(0,1) and (1,1)(1,1) (as the red numbers in the figure), then for path P1P_1 we get s(P1)=011s(P_1) = 011, and for path P2P_2 we get s(P2)=001s(P_2) = 001.

The game requires Xiao D to find a way to fill 00 and 11 such that for any two paths P1P_1, P2P_2, if w(P1)>w(P2)w(P_1) > w(P_2), then it must hold that s(P1)s(P2)s(P_1) \le s(P_2). We say that string aa is smaller than string bb if and only if aa is lexicographically smaller than bb. The definition of lexicographical order is given in detail in Problem 1. However, finding just one method does not satisfy Xiao D’s curiosity. Xiao D wants to know how many different ways the game can be played, that is, how many filling methods satisfy the requirement.

Xiao D is not strong enough, so he hopes you can help solve this problem: how many ways of filling 00 and 11 can satisfy the requirement? Since the answer may be very large, you need to output the answer modulo 109+710^9 + 7.

Input Format

The input consists of one line containing two positive integers n,mn,m, separated by a space, representing the size of the rectangle. Here nn is the number of rows of the grid, and mm is the number of columns of the grid.

Output Format

Output one line containing a positive integer, representing how many ways of filling 00 and 11 can satisfy the requirement. Note: output the result modulo 109+710^9+7.

2 2
12
3 3
112
5 5
7136

Hint

Sample Explanation

Constraints

Test Point ID nn\le mm\le
141\sim 4 33
5105\sim 10 22 10610^6
111311\sim 13 33
141614\sim 16 88 88
172017\sim 20 10610^6

Translated by ChatGPT 5