Hive
Time limit1sMemory limit256 MB
Each rabbit walks a right-or-down path from the top-left cell to the bottom-right cell, and the goal is the fewest paths covering every flower.
- Level
Hard8 of 10
- Topics
- Graph, Combinatorics, Greedy, Sorting
- Solved
- No attempts yet
Problem
A field of pink flowers is divided into rows and columns of one square meter cells. The cell in row from the top and column from the left holds flowers.
Every morning a group of rabbits comes to eat the flowers so that their fur turns pink. A rabbit starts at the top left cell and travels to the bottom right cell, moving one cell right or one cell down at a time. It never goes back to the left and never goes back up. Whenever a rabbit enters a cell that still holds at least one flower, it picks exactly one flower there. It walks past a cell with no flowers left without picking anything.
You may choose the route of every rabbit. Find the smallest number of rabbits needed to pick every flower in the field.
Input
The first line contains the number of test cases ().
The first line of each test case contains the number of rows and columns of the field, and ().
Each of the next lines contains integers. The -th integer on the -th line is ().
Output
For each test case, print the smallest number of rabbits needed to pick every flower, one answer per line.