Transmission Door
Fate
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 15547 Accepted Submission (s): 5442
Problem Description
Passing through the Glen means that the great Lord Lemon has been infinitely close!
But who can think, Yifenfei in kill some cats, but again face the fate of the maze of the test, this is the Devil lemon set up another organ. You know, whoever, if trapped in the maze for more than 1 hours, will surely die!
Poor Yifenfei in order to save mm, righteousness without return to jump into the maze. Let us help to help the persistent him!
The great maze of destiny can be seen as a two-dimensional grid array, as shown in:
Yifenfei first in the upper left corner, the aim of course is to reach the lower right corner of the great Lord's seat. Every lattice in the maze is cursed by the goddess of luck or the devil, so each grid corresponds to a value, where it automatically gets the corresponding value.
It is now stipulated that Yifenfei can only go to the right or down and only one grid at a time. But if you go to the right, you can walk one block at a time or go to the number of columns that are currently in the number of columns, that is: if the current lattice is (x, y), the next step can be (x+1,y), (x,y+1) or (x,y*k) where k>1.
In order to be able to best grasp the eradication of the Devil Lemon,yifenfei hope to be able to get the greatest fortune in this maze of fate.
Input
The input data is first an integer c, which represents the number of groups of test data.
The first line of each set of test data is two integer n,m, representing the number of rows and columns (1<=n<=20,10<=m<=1000);
followed by n rows of data, each containing M integers representing the lucky value K (|k|<100) for the lattice of the N row M column.
Output
Please output an integer for each set of test data, indicating the maximum lucky value that Yifenfei can get.
Sample Input
1
3 8
9 10 10 10 10-10 10 10
10-11-1 0 2 11 10-20
-11-11 10 11 2 10-10-10
Sample Output
52
Author
Yifenfei
Problem Solving Ideas:
We should do the question of the number of towers, this topic is similar to that, first we set DP[I][J] to represent the row J column of the maximum lucky value of the lattice, then it is how it came, we can analyze it, because it can only go to the right or down there is its multiple lattice walk, it must be by dp[ I-1][J] and dp[i][j-1] come, and then it's the number of factors, we each time is the maximum value, that is, Max (Dp[i-1][j],dp[i][j-1]), and then a loop to find the factor, you can, notice that the initialization should be the minimum value, (with negative numbers)
On the code:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>using namespace STD;Const intMAXN =1e3+5;Const intINF =1e9+5;inta[ -][MAXN];intdp[ -][MAXN];intN, M;voidInit () { for(intI=0; i<=n; i++) for(intj=0; j<=m; J + +) dp[i][j] =-inf;}intMain () {intTscanf("%d", &t); while(t--) {scanf("%d%d", &n,&m); Init ();memsetA0,sizeof(a)); for(intI=1; i<=n; i++) { for(intj=1; j<=m; J + +) {scanf("%d", &a[i][j]); }} dp[1][0] = dp[0][1] = dp[0][0] =0; for(intI=1; i<=n; i++) { for(intj=1; j<=m; J + +) {Dp[i][j] = max (dp[i-1][j],dp[i][j-1]); for(intk=2; k<=m; k++) {if(J%k = =0) Dp[i][j] = max (dp[i][j],dp[i][j/k]); } Dp[i][j] + = a[i][j]; } }cout<<dp[n][m]<<endl; }return 0;}/** _ooooo_ o8888888o 88 ". "88 (| -_- |) o\ =/o ____/'---' \____. ' \\| |// `. / \\||| : ||| // / _||||| -:- ||||| - | | \\\ - /// | | | \_| ' \---/' | | \ .-\__ `-` ___/-. / ___`. .‘ /--.--\ `. . __ ."" ' < '. ___\_<|>_/___. ' > ' "". | | : `- \`.; `\ _ /`;. `/ - ` : | | \ \ `-. \_ __\/__ _/.-'//====== '-.____ '-.___\_____/___.-' ____.-' ====== ' =---= ' ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ Buddha bless every ac**/
HDU 2571 fate (Simple DP)