This question is more restrictive than that of poj. It defines the size of the sub-matrix, starting to see the time of 10 s, decisive violence, then decisive TLE, and a little bit of optimization or TLE!
Then we use DP. How is DP used? It is very simple, so that a [I] [J] is 1 <= S <= I, 1 <= T <= J, and can be processed online, then, you can use addition and subtraction to obtain the current sub-matrix and, just like calculating several matrix areas (some parts are covered together, so they are added and subtracted from the repeated area ).
# Include <vector> # include <list> # include <map> # include <set> # include <queue> # include <string. h> # include <deque> # include <stack> # include <bitset> # include <algorithm> # include <functional> # include <numeric> # include <utility> # include <sstream> # include <iostream> # include <iomanip> # include <cstdio> # include <cmath> # include <cstdlib> # include <limits. h> using namespace STD; int lowbit (INT t) {return T & (-T);} in T countbit (INT t) {return (t = 0 )? 0 :( 1 + countbit (T & (t-1);} int gcd (int A, int B) {return (B = 0 )? A: gcd (B, A % B);} int max (int A, int B) {return A> B? A: B;} int min (int A, int B) {return A> B? B: A ;}# define ll long # define PI ACOs (-1.0) # define n 1010 # define Max int_max # define min int_min # define EPS 1e-8 # define fre freopen ("a.txt", "r", stdin) int n, m, X, Y; int a [n] [N]; int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M, & X, & Y); int I, j; int ans =-1; memset (A, 0, sizeof (a); for (I = 1; I <= N; I ++) {for (j = 1; j <= m; j ++) {scanf ("% d", & A [I] [J]); A [I] [J] + = A [I-1] [J] + A [I] [J-1]-A [I-1] [J-1]; if (I> = x & J> = y) {int TMP = A [I] [J]-A [I-x] [J]-A [I] [J-y] + A [I-x] [J -Y]; if (TMP> ans) ans = TMP ;}} printf ("% d \ n", ANS);} return 0 ;}