#P8612. [蓝桥杯 2014 省 AB] 地宫取宝
[蓝桥杯 2014 省 AB] 地宫取宝
Description
The king of Country X has an underground palace treasure vault. It is a matrix of cells. Each cell contains one treasure. Each treasure has a value tag.
The entrance of the underground palace is at the top-left corner, and the exit is at the bottom-right corner.
Xiaoming is brought to the entrance, and the king requires that he may only move right or down.
When passing through a cell, if the treasure value in that cell is greater than the value of any treasure currently in Xiaoming’s hand, Xiaoming may pick it up (of course, he may also choose not to).
When Xiaoming reaches the exit, if he has exactly treasures in his hand, then these treasures will be given to him.
Please help Xiaoming compute: under the given situation, how many different action plans allow him to obtain these treasures.
Input Format
The first line contains integers separated by spaces: , , .
Then follow lines of data. Each line contains integers , representing the value of the treasure in that cell.
Output Format
Output one integer, representing the number of action plans that pick exactly treasures. This number may be very large; output it modulo .
2 2 2
1 2
2 1
2
2 3 2
1 2 3
2 1 5
14
Hint
Time limit: 1 second, 256M. The 5th Lanqiao Cup Provincial Contest in 2014.
Translated by ChatGPT 5
京公网安备 11011102002149号