UVA-10755 Garbage Heap 三维子矩阵最大和
2014-04-26 19:53
447 查看
#include <cstdlib> #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; const LL INF = 1LL<<60; int A, B, C; LL sumz[25][25][25]; // 平面上[1,1]到[i][j]在高度为k时的区域前缀和 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() { // 需要枚举平面上的二维组合 LL ret = -INF; LL Min, s; for (int i = 1; i <= A; ++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 %d %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; }
相关文章推荐
- UVA-10755 Garbage Heap 三维子矩阵最大和
- UVA - 10755 Garbage Heap 三维子矩阵最大和(压缩)
- UVA 10755 - Garbage Heap(三维子矩阵最大和)
- Uva 10755 Garbage Heap(三维最大子矩阵)
- uva 10755 - Garbage Heap(三维最大子矩阵)
- UVa 10755 - Garbage Heap 三维最大子矩阵问题转化为1维..
- 【降维解法:最大字段和->最大子矩阵和->最终版最大子长方体和】【UVA10755】Garbage Heap
- UVa 10755 Garbage Heap (最大价值子立方体+扫描法)
- 【降维解法:最大字段和->最大子矩阵和->最终版最大子长方体和】【UVA10755】Garbage Heap
- UVa 10755 - Garbage Heap 最大子块和 dp
- 【UVa】10755 Garbage Heap 三维前缀和
- UVa 10755 - Garbage Heap 最大子块和 dp
- UVA 10755 Garbage Heap 三维最大子矩阵和 -
- uva10755 - Garbage Heap (最大子立方体)
- UVA 10755 Garbage Heap(最大子长方体 可拓展更高维)
- uva10755 - Garbage Heap 找最大子立方体
- UVA 10755 Garbage Heap 最大子立方体和
- uva 10755 - Garbage Heap(最大和问题)
- UVA 10074 Take the Land(最大子矩阵和变形)
- URAL_1146/uva_108 最大子矩阵 DP 降维