Question: the largest sum of 3D submatrices.
Solution: enumerate the two dimensions of a three-dimensional plane, and then convert the third dimension to a linear solution. The time complexity O (N ^ 5) is read into the data azimuth pitfall, the absolute value cannot exceed 2 ^ 31. There is no problem with the negative number. The maximum positive integer in int form is 2 ^ 31-1 ...... as a result, WAF is always crying.
The Code is as follows:
# Include <cstdlib> # include <cstdio> # include <iostream> # include <algorithm> # include <cstring> using namespace STD; typedef long ll; const ll INF = 1ll <60; int A, B, C; ll sumz [25] [25] [25]; // The prefix of the region [] to [I] [J] on the plane when the height is K and ll get (INT X1, int Y1, int X2, int Y2, int Z) {return sumz [X2] [y2] [Z]-sumz [x1-1] [y2] [Z]-sumz [X2] [y1-1] [Z] + sumz [x1-1] [y1-1] [Z];} void solve () {// two-dimensional combination ll ret =-INF; ll min, s; For (INT I = 1; I <=; ++ I) {for (Int J = I; j <= A; ++ J) {for (int K = 1; k <= B; ++ K) {for (int h = K; H <= B; ++ h) {min = 0; For (INT p = 1; P <= C; ++ P) {S = get (I, K, J, H, P); ret = max (Ret, S-min); If (S <min) min = s ;}}}} printf ("% LLD \ n", RET);} int main () {int t; scanf ("% d ", & T); While (t --) {scanf ("% d", & A, & B, & C); LL tot, X; for (INT I = 1; I <= A; ++ I) {for (Int J = 1; j <= B; ++ J) {tot = 0; for (int K = 1; k <= C; ++ K) {scanf ("% LLD", & X); Tot + = X; sumz [I] [J] [k] = sumz [I-1] [J] [k] + sumz [I] [J-1] [k]-sumz [I-1] [J-1] [k] + tot ;}}} solve (); If (t) puts ("") ;}return 0 ;}