cswork / OA打开练习工作台

Hudson River TradingOA #5

Increasing Paths, part 1

估计中等可在线判题

考点(AI 标注)树形博弈网格搜索

A path in the grid consists of at least two cells; consecutive cells must be adjacent up, down, left or right, and the value must strictly increase at each step. Paths are distinguished by their sequence of cell positions. Count all increasing paths; the number of paths is guaranteed not to exceed 2000.

The original example output of 4 matches the adjacency path definition, but the listed path endpoints were described inaccurately: the actual four paths are 1→5, 1→2, 2→7 and 1→2→7. This site keeps the rule and the answer, corrects the description, and records the error in the original explanation.

输入格式

The first line contains the number of rows R (1..15); each of the next R lines first gives the number of columns C_r (1..15), then the C_r integers of that row (0..65535). Rows may have different lengths; only cells that exist can be adjacent.

输出格式

Output the total number of strictly increasing paths of length at least 2.

样例 1

输入:

3
1 5
1 1
2 2 7

输出:

4

样例 2

输入:

1
1 9

输出:

0

样例 3

输入:

2
2 1 2
1 2

输出:

2