HDU 2571 fate (motion regulation)

Source: Internet
Author: User
Fate Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 9334 accepted submission (s): 3289



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
 
Authoryifenfei
Sourceacm Program Design final exam 081230 question: By the way of the question, find the biggest lucky value. I can't think of it. View others' problem-solving reports. OTL.
Recommendyifenfei | we have carefully selected several similar problems for you: 1421 2577 1505 2870
This code is to generalize special cases, so there is no judgment in the core operations of the dynamic rule.
Code: 187 Ms
# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm>Using namespaceSTD;# Define n 25 # define M 1005 # define INF-99999IntMap[N] [M],DP[N] [M]; Int main () {intI,N,M,T,J,K; While (CIN>T) {While (T--){CIN>N>M; (I=1;I<=N;I++) (J=1;J<=M;J++)CIN>Map[I] [J]; (I=0;I<=N;I++)DP[I] [0] =INF; // There is a negative number. If the value is null, it is very likely that the value will be taken from outside the boundary. The sample can also be used. For (I=0;I<=M;I++)DP[0] [I] =INF;DP[0] [1] =DP[1] [0] =0; // The origin is a special case. Its value is only from outside the boundary, so its value can only be zero. For (I=1;I<=N;I++) // The pre-stage is initialized in special cases. For (J=1;J<=M;J++ ){// Note: There is an empty table in DP, and the values are all in map. DP[I] [J] =Max(DP[I-1] [J],DP[I] [J-1]); (K=2;K<=M;K++) If (J/K= (Double)J/K)DP[I] [J] =Max(DP[I] [J],DP[I] [J/K]);DP[I] [J] + =Map[I] [J]; // The previous DP [I] [J] is the maximum luck value that can reach this point. Now we need to add the value of this point. }Cout<DP[N] [M] <Endl;} Return0;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.