Algorithm concept: Dynamic Planning
State transition equation: score [I] [J] = max {score [I + 1] [J], score [I] [J + 1], score [I] [J * k]}, k> 1.
Specific implementation: the recursive method is used. The boundary value is taken into account separately, and then the square in the inner layer is recursive using a two-layer loop.
// Template start # include <string> # include <vector> # include <algorithm> # include <iostream> # include <sstream> # include <fstream> # include <map> # include <set> # include <cstdio> # include <cmath> # include <cstdlib> # include <ctime> # include <iomanip> # include <string. h> # define SZ (x) (INT (X. size () using namespace STD; int toint (string s) {istringstream sin (s); int t; sin> T; return t ;} template <class T> string TOST Ring (t x) {ostringstream sout; sout <X; return sout. STR ();} typedef long int64; int64 toint64 (string s) {istringstream sin (s); int64 t; sin> T; return t ;} template <class T> T gcd (t a, t B) {if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} // template end (General Part) # define ifs CIN # define max_row 25 # define max_col 1005int cases; int n, m; int data [max_row] [max_col]; int score [max_row] [max_col]; void dp () {score [N] [m] = data [N] [m]; for (INT I = n-1; I> = 1; I --) {score [I] [m] = score [I + 1] [m] + data [I] [m];} For (Int J = m-1; j> = 1; j --) {score [N] [J] = score [N] [J + 1] + data [N] [J];} for (INT I = n-1; I> = 1; I --) {for (Int J = m-1; j> = 1; j --) {score [I] [J] = score [I + 1] [J] + data [I] [J]; if (score [I] [J + 1] + data [I] [J]> score [I] [J]) {score [I] [J] = score [I] [J + 1] + data [I] [J];} For (int K = 2; K * j <= m; k ++) {If (score [I] [K * j] + data [I] [J]> score [I] [J]) {score [I] [J] = score [I] [K * j] + data [I] [J] ;}}} // [exercise 09] Simple and dynamic planning 1003 super jumping! Jumping! Jumping! Int main () {// ifstream ifs ("shuju.txt", IOS: In); ifs> cases; for (INT I = 0; I <cases; I ++) {ifs> N> m; For (Int J = 1; j <= N; j ++) {for (int K = 1; k <= m; k ++) {ifs> data [J] [k] ;}} dp (); cout <score [1] [1] <Endl ;} return 0 ;}