Codeforces Round #245 (Div. 1) B recurrence DP
The intersection of a 1000*1000 graph is one, and how to draw a picture at the same point can be found in two cases, so the first thing that comes to mind is that the intersection can be enumerated violently, then push forward by the intersection point. After the intersection, the two people continue to move forward to their own destination. Therefore, we can enumerate and roll out the maximum values of each vertex to the four vertices of the graph, then we can obtain the optimal one based on the intersection conditions.
Int mp [1000 + 55] [1000 + 55]; int dp1 [1000 + 55] [1000 + 55], dp2 [1000 + 55] [1000 + 55], dp3 [1000 + 55] [1000 + 55], dp4 [1000 + 55] [1000 + 55]; int n, m; void init () {memset (mp, 0, sizeof (mp); memset (dp1, 0, sizeof (dp1); memset (dp2, 0, sizeof (dp2); memset (dp3, 0, sizeof (dp3); memset (dp4, 0, sizeof (dp4);} bool input () {while (cin> n> m) {for (int I = 1; I <= n; I ++) for (int j = 1; j <= m; j ++) scanf ("% d ", & amp; mp [I] [j]); return false;} return true;} void cal () {for (int I = 1; I <= n; I ++) for (int j = 1; j <= m; j ++) dp1 [I] [j] = mp [I] [j] + max (dp1 [I-1] [j], dp1 [I] [j-1]); // recursive the current vertex to the top left vertex with the largest value for (int I = 1; I <= n; I ++) for (int j = m; j> 0; j --) dp2 [I] [j] = mp [I] [j] + max (dp2 [I-1] [j], dp2 [I] [j + 1]); // top right... for (int I = n; I> 0; I --) for (int j = 1; j <= m; j ++) dp3 [I] [j] = mp [I] [j] + max (dp3 [I + 1] [j], dp3 [I] [j-1]); // bottom left... for (int I = n; I> 0; I --) for (int j = m; j> 0; j --) dp4 [I] [j] = mp [I] [j] + max (dp4 [I + 1] [j], dp4 [I] [j + 1]); // ...int ans = 0 at the bottom of the right;/* indicates the violent enumeration intersection. The intersection is a */for (int I = 2; I