AC代码
#include <cstdio>
#include <cstring>
long long a[21][21][21];
int main()
{
// freopen("i.txt", "r", stdin);// freopen("o.txt", "w", stdout);int t; scanf("%d", &t);while(t--){
int A, B, C; scanf("%d%d%d", &A, &B, &C);memset(a, 0, sizeof(a));for(int i = 1; i <= A; i++)for(int j = 1; j <= B; j++)for(int k = 1; k <= C; k++){
scanf("%lld", &a[i][j][k]);a[i][j][k] += a[i - 1][j][k] + a[i][j - 1][k] + a[i][j][k - 1]- a[i - 1][j - 1][k] - a[i - 1][j][k - 1] - a[i][j - 1][k - 1]+ a[i - 1][j - 1][k - 1]; }long long max = a[1][1][1];for(int i = 1; i <= A; i++)for(int j = 1; j <= B; j++)for(int k = 1; k <= C; k++)for(int i2 = i; i2 <= A; i2++)for(int j2 = j; j2 <= B; j2++)for(int k2 = k; k2 <= C; k2++){
long long sum = a[i2][j2][k2] - a[i - 1][j2][k2] - a[i2][j - 1][k2] - a[i2][j2][k - 1]+ a[i - 1][j - 1][k2] + a[i - 1][j2][k - 1] + a[i2][j - 1][k - 1]- a[i - 1][j - 1][k - 1];max = sum > max ? sum : max;}printf("%lld\n", max);if(t) putchar('\n');}
}