#P12415. Counting Trees on a Grid
Counting Trees on a Grid
Counting Trees on a Grid
You are given a grid with n rows and m columns. Your task is to construct a tree subject to the following conditions:
- Each node of the tree is placed in a grid cell, and each cell may contain at most one node.
- If a node is assigned to cell at row i and one of its children is placed in a cell at row j, then it must hold that i < j (i.e. the row numbers of any node are strictly less than the row numbers of all of its children).
The tree is unlabelled (i.e. all nodes are identical). Two trees are considered the same if all of the following hold:
- They contain the same number of nodes.
- If we denote by S1 and S2 the sets of grid cells occupied by nodes in the two trees, then S1 = S2.
- The parent–child relationships between nodes in corresponding cells are exactly the same. More formally, for every cell x in S1 (and hence in S2), if the sets of cells to which the children of the node in x are mapped are S'1 and S'2 respectively, then S'1 = S'2.
Count the number of different trees that can be constructed on the grid. Output the answer modulo \(10^9+7\).
inputFormat
The input consists of a single line containing two integers n and m (n rows and m columns), separated by a space.
outputFormat
Output a single integer: the number of trees that can be constructed on the grid, modulo \(10^9+7\).
sample
1 1
1