Dynamic Planning and search, wrong once, we know the direction of each move, search to select the maximum value, no need to save the results of another array, add an access array visit, the original access has obtained the maximum value, and the maximum value can be returned as long as the access has passed.
Code:
[Cpp]
# Include <iostream>
Const int INF =-100000000;
Using namespace std;
Int map [22] [1002];
Bool visit [22] [1, 1002];
Int n, m;
Int DFS (int I, int j)
{
If (visit [I] [j] | I = n & j = m)
Return map [I] [j];
Int mx = INF;
If (I + 1 <= n) mx = max (mx, DFS (I + 1, j ));
If (j + 1 <= m) mx = max (mx, DFS (I, j + 1 ));
For (int k = 2; k * j <= m; k ++)
Mx = max (mx, DFS (I, k * j ));
Map [I] [j] + = mx; // use map to save the result.
Visit [I] [j] = true;
Return map [I] [j];
} Www.2cto.com
Int main ()
{
Int c, I, j;
Scanf ("% d", & c );
While (c --){
Scanf ("% d", & n, & m );
Memset (map, 0, sizeof (map ));
Memset (visit, 0, sizeof (visit ));
For (I = 1; I <= n; I ++)
For (j = 1; j <= m; j ++)
Scanf ("% d", & map [I] [j]);
Printf ("% d \ n", DFS (1, 1 ));
}
Return 0;
}
Author: aacm1992