#P3974. [TJOI2015] 组合数学
[TJOI2015] 组合数学
Description
To improve her IQ, ZJY started studying combinatorics. One day she solved this problem: given a grid where some cells contain treasure. Each time, starting from the top-left corner, you can only move right or down. What is the minimum number of walks needed so that it is possible to collect all the treasures?
But she was not satisfied and thought of a variation: suppose each cell contains many pieces of treasure, and on each pass through a cell you can take at most one piece of treasure. With other conditions unchanged, what is the minimum number of walks needed so that it is possible to collect all the pieces of treasure?
This time she could not solve it. Can you help her?
Input Format
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains two positive integers and , indicating the grid has rows and columns.
The next lines each contain non-negative integers, representing the number of pieces of treasure in that cell ( means no treasure).
Output Format
For each test case, output one integer, the minimum number of walks.
1
3 3
0 1 5
5 0 0
1 0 0
10
Hint
Constraints
For of the testdata, , , and the number of pieces of treasure in each cell does not exceed .
For of the testdata, , , and the number of pieces of treasure in each cell does not exceed .
For of the testdata, , , , and the number of pieces of treasure in each cell does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号