(高效算法设计)之高维问题 废料堆 Garbage heap Uva 10755
2015-02-07 15:13
525 查看
#include <iostream> #include <algorithm> #define FOR(i,s,p) for(int i=(s);i<=(p);i++) using namespace std; void expand(char i, bool b[]){ b[0] = i & 1; i >>= 1; b[1] = i & 1; i >>= 1; b[2] = i & 1; } // 这里使用了二项式中的思想, 3个k char sign(bool b[]){ return (b[0] + b[1] + b[2]) % 2 == 1 ? -1 : 1; } const int maxn = 30; const long long INF = 1LL << 60; long long S[maxn][maxn][maxn]; long long sum(int x1, int x2, int y1, int y2, int z1, int z2){ int dx = x2 - x1 + 1, dy = y2 - y1 + 1, dz = z2 - z1 + 1; long long s = 0; bool b[3]; for (int i = 0; i < 8; i++){ expand(i, b); s += (S[x1 + dx*b[0]][y1 + dy*b[1]][z1 + dz*b[2]])*sign(b); } return s; } int main(){ int T; cin >> T; while (T--) { int a, b, c; bool bb[3]; 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 (char i = 1; i <= 7;i++) { expand(i, bb); S[x][y][z] += S[x - bb[0]][y - bb[1]][z - bb[2]] * sign(bb);; } long long ans = -INF; long long M=0; FOR(x1, 1, a)FOR(x2, x1, a)FOR(y1, 1, b)FOR(y2, y1, b)FOR(z, 1, c){ long long s = sum(x1, x2, y1, y2, 1, z); ans = max(s-M , ans); M = min(M, s); } cout << ans; if (T) cout << '\n'; } return 0; }
相关文章推荐
- 【高效算法设计——最大值最小问题】UVa 714 Coying Books
- 高效算法设计专项:UVa 10730
- 高效算法设计专项:UVa 10691
- 【高效算法设计——双向扫描】 UVa 1442 Cave
- UVA 10755 Garbage Heap 三维最大子矩阵和 -
- 集训第四周(高效算法设计)K题 (滑窗问题)
- 高效算法设计专项:UVa 10535
- 【高效算法设计——递归】 UVa 1608 Non-boring sequences
- 【高效算法设计——二分法】UVa 1607 Gates
- 紫书_第八章_高效算法设计_8.3.2——循环日程表问题
- 高效算法设计专项:UVa 11572
- 【高效算法设计——等价转换】UVa 11054
- ( 设计高效算法 ) 年龄排序 Age Sort Uva 11462
- 集训第四周(高效算法设计)D题 (区间覆盖问题)
- 高效算法设计专项:UVa 10391
- 高效算法设计专项:UVa 10827
- 【高效算法设计】UVa120 Stack of Flapjacks
- 【高效算法设计——问题分解】Uva11134 Fabled Rooks
- 算法竞赛入门经典:第八章 高效算法设计 8.16贪心之乘船问题
- 集训第四周(高效算法设计)E题 (区间覆盖问题)