QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100 难度: [显示] 可 Hack ✓

#6494. Number Filling Game

统计

Little D loves filling games. Today, he is playing a filling game.

The board for this filling game is an $n \times m$ rectangular grid. The player needs to fill each cell of the grid with a digit (either 0 or 1), and the filling must satisfy certain constraints.

We describe these constraints in detail below. To facilitate the description, we first provide some definitions: We use the row and column coordinates of a cell to represent it, i.e., (row coordinate, column coordinate). (Note: Both row and column coordinates are 0-indexed.) A valid path $P$: A path is valid if and only if: 1. The path starts from the top-left cell $(0,0)$ of the rectangular grid and ends at the bottom-right cell $(n-1, m-1)$. 2. In this path, one can only move from the current cell to the adjacent cell on the right, or from the current cell to the adjacent cell below.

For example, in the rectangle below, there are two valid paths, which are $P_1: (0,0) \to (0,1) \to (1,1)$ and $P_2: (0,0) \to (1,0) \to (1,1)$.

For a valid path $P$, we can represent it with a string $w(P)$ of length $n+m-2$, which contains only the characters "R" or "D". The $i$-th character records the $i$-th move in path $P$, where "R" represents moving to the adjacent cell on the right, and "D" represents moving to the adjacent cell below. For example, in the figure above for path $P_1$, $w(P_1) = \text{"RD"}$; for the other path $P_2$, $w(P_2) = \text{"DR"}$.

At the same time, concatenating the digits filled in the cells that a valid path $P$ passes through yields a 01-string of length $n+m-1$, denoted as $s(P)$. For example, if we fill the cells $(0,0)$ and $(1,0)$ with the digit 0, and fill the cells $(0,1)$ and $(1,1)$ with the digit 1 (see the red digits in the figure above), then for path $P_1$, we get $s(P_1) = \text{"011"}$, and for path $P_2$, $s(P_2) = \text{"001"}$.

The game requires Little D to find a way to fill the digits 0 and 1 such that for any two valid paths $P_1$ and $P_2$, if $w(P_1) > w(P_2)$, then $s(P_1) \le s(P_2)$. We say string $a$ is smaller than string $b$ if and only if the lexicographical order of string $a$ is less than the lexicographical order of string $b$. Little D wants to know how many ways there are to fill the digits to satisfy the game's requirements.

Little D has limited ability and hopes you can help him solve this problem, i.e., how many ways to fill 0s and 1s satisfy the problem requirements. Since the answer can be very large, you need to output the answer modulo $10^9 + 7$.

Input

The input consists of a single line containing two integers $n$ and $m$, separated by a space, representing the size of the rectangle. $n$ represents the number of rows in the rectangular grid, and $m$ represents the number of columns in the rectangular grid.

Output

Output a single line containing an integer, representing the number of ways to fill the digits 0 and 1 that satisfy the game's requirements. Note: Output the answer modulo $10^9 + 7$.

Examples

Input 1

2 2

Output 1

12

Note 1

For a $2 \times 2$ board, the 12 filling methods shown in the figure above satisfy the requirements.

Input 2

3 3

Output 2

112

Input 3

5 5

Output 3

7136

Constraints

Test Case ID $n \le$ $m \le$
1~4 3 3
5~10 2 1000000
11~13 3 1000000
14~16 8 8
17~20 8 1000000

Figure 1. A $2 \times 2$ grid showing valid paths.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.