/***********************************************
* Author: fisty
* Created Time: 2015/1/25 15:49:25
* File Name : uva.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define FOR(i, s, t) for(int i = (s); i <= (t); ++i)
#define MAX_N 30
const long long INF = 1LL << 60;
typedef long long LL;
typedef pair<int, int> P;
LL S[MAX_N][MAX_N][MAX_N];
void expand(int i, int &b0, int &b1, int &b2){
b0 = i&1;i >>= 1;
b1 = i&1;i >>= 1;
b2 = i&1;
}
int sign(int b0, int b1, int b2){
//和是奇数返回1
return (b0 + b1 + b2) % 2 == 1 ? 1 : -1;
}
LL sum(int x1, int x2, int y1, int y2, int z1, int z2){
int dx = x2 - x1 + 1;
int dy = y2 - y1 + 1;
int dz = z2 - z1 + 1;
LL s = 0;
for(int i = 0;i < 8; i++){
int b0, b1, b2;
expand(i, b0, b1, b2);
s -= S[x2-b0*dx][y2-b1*dy][z2-b2*dz] * sign(b0, b1, b2);
}
return s;
}
int main() {
//freopen("in.txt", "r", stdin);
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int a, b, c, b0, b1, b2;
cin >> a >> b >> c;
memset(S, 0, sizeof(S));
FOR(x, 1, a) FOR(y, 1, b) FOR(z, 1, c) cin >> S[x][y][z];
FOR(x, 1, a) FOR(y, 1, b) FOR(z, 1, c) FOR(i, 1, 7){
expand(i, b0, b1, b2);
//Debug(b0);
//Debug(b1);
//Debug(b2);
S[x][y][z] = S[x][y][z] + S[x-b0][y-b1][z-b2] * sign(b0,b1,b2);
}
LL ans = -INF;
FOR(x1, 1, a) FOR(x2, x1, a) FOR(y1, 1, b) FOR(y2, y1, b){
LL M = 0;
FOR(z, 1, c){
LL s = sum(x1,x2,y1,y2,1,z);
ans = max(ans, s - M);
M = min(M, s);
}
}
cout << ans << endl;
if(t)
cout << endl;
}
return 0;
}
uva10755 - Garbage Heap (最大子立方体)
最新推荐文章于 2019-06-07 12:52:15 发布