Labyrinth
Problem Description
Du du Xiong is a bear who loves adventure. He accidentally falls into a m * n matrix maze, which can only start from the first square in the upper left corner of the matrix, only the first grid in the upper-right corner can be used to walk out of the maze. Each grid can only go up and down to the right to go to the grid that has not been traveled before. Each grid has some gold coins (either positive or negative, there may be a robber in the Road robbery. The gold coins on Dudu Xiong can be negative, and you need to write an overdue bill to the robbers. At the beginning, Dudu Xiong's gold coins were 0, q: How many gold coins does du Xiong have when he walks out of the maze?
Input
The first line of the input is an integer T (T <200), indicating a total of T groups of data. Enter two positive integers m, n (m <= 100, n <= 100) in the first row of each data group ). In the next m row, n integers in each line represent the number of gold coins in the corresponding grid. Each integer is greater than or equal to-100 and less than or equal to 100.
Output
For each group of data, you must first output a separate line "Case #? : ", Where the question mark should be filled with the current number of data groups. The number of groups starts from 1. Each group of test data outputs a row and an integer, which indicates the maximum number of coins you can obtain when you go to the upper right corner Based on the optimal strategy.
Sample Input
2
3 4
1-1 1 0
2-2 4 2
3 5 1-90
2 2
1 1
1 1
Sample Output
Case #1:
18
Case #2:
4
If the maze is large, DFS will inevitably time out. Note that there are only three walking directions: top, bottom, and right. This means that the road that has been traveled cannot be walked any more, and that you do not need to trace back. The question is the maximum value. Everything clearly points to DP!
Time Complexity: O (n * m ).