Reprinted please indicate the source: http://blog.csdn.net/u012860063
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2571
Problem description passes through the valley, which means that Lemon is infinitely close to the devil!
Who can think of it? yifenfei, after killing some shrimps and crabs, is once again facing the test of the fate of the maze. This is another organ set up by Lemon, the devil. You know, no matter who you are, if you have been trapped for more than an hour in the maze, you will surely die!
Poor yifenfei jumped into the maze to save mm. Let's help him!
The fate maze can be viewed as a two-dimensional square array, as shown in:
Yifenfei is initially in the upper left corner. The goal is to reach the location of the big devil in the lower right corner. Every grid in the maze is cursed by the goddess of luck or the devil of pain. Therefore, each grid corresponds to a value, and the corresponding value is automatically obtained when it comes to it.
Currently, yifenfei can only go to the right or down, and only one grid can go down at a time. However, if you go to the right, the number of columns that can go to a grid or the row is the number of grids in multiples of the current number of columns. That is, if the current grid is (x, y ), the next step can be (x + 1, Y), (X, Y + 1), or (x, y * k) where k> 1.
Yifenfei hopes to get the biggest lucky value in this destiny maze to eliminate lemon.
The input data is an integer c, indicating the number of test data groups.
The first row of each group of test data is two integers, N and M, indicating the number of rows and columns respectively (1 <=n <= 20, 10 <= m <= 1000 );
Next is n rows of data. Each row contains M integers, indicating the lucky value K (| K | <100) corresponding to the lattice of M columns in N rows ).
Output outputs an integer corresponding to each group of test data, indicating the maximum lucky value that yifenfei can obtain.
Sample Input
13 89 10 10 10 10 -10 10 1010 -11 -1 0 2 11 10 -20-11 -11 10 11 2 10 -10 -10
Sample output
52
You do not need to explain the meaning in Chinese!
The Code is as follows:
# Include <cstdio> int max (int A, int B) {If (A> B) return a; return B;} int f [22] [1, 1047]; int main () {int n, m, T, I, J, K, C; scanf ("% d", & C); While (c --) {scanf ("% d", & N, & M); for (I = 1; I <= N; I ++) for (j = 1; j <= m; j ++) {scanf ("% d", & F [I] [J]) ;}for (I = 0; I <= N; I ++) // The value of F [I] [0] =-1000; for (I = 0; I <= m; I ++) // set as the lower bound value f [0] [I] =-1000; for (I = 1; I <= N; I ++) {for (j = 1; j <= m; j ++) {if (I = 1 & J = 1) continue; t = f [I] [J-1]; // The row is directed to the right side of the grid for (k = 2; k <= J; k ++) // calculate the maximum value of F [I] [J] If (J % K = 0) if (T <F [I] [J/K]) t = f [I] [J/K];} f [I] [J] + = max (F [I-1] [J], t ); // compare the maximum value that can be reached in the same row with the maximum value that can be reached in the next row} printf ("% d \ n", F [N] [m]);} return 0 ;}