<h1 style="MARGIN-BOTTOM: 0px; FONT-FAMILY: 'times new roman'; FONT-VARIANT: normal; WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT-STYLE: normal; LETTER-SPACING: normal; LINE-HEIGHT: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Garbage Heap</span></h1><div class="constraints" style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Time limit: ? seconds</span></div><div class="constraints" style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Memory limit: 64 megabytes</span></div><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Farmer John has a heap of garbage formed in a rectangular parallelepiped.</span></p><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">It consists of<span> </span><img class="mathimg" alt="$A\times B\times C$" src="http://uva.onlinejudge.org/external/107/p107551.png" width="85" height="13" /><span> </span>garbage pieces each of which has a value. The value of a piece may be 0, if the piece is neither profitable nor harmful, and may be negative which means that the piece is not just unprofitable, but even harmful (for environment).</span></p><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"></span></p><center style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"><img src="http://uva.onlinejudge.org/external/107/p10755_1.png" alt="" /></span></center><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">The farmer thinks that he has too much harmful garbage, so he wants to decrease the heap size, leaving a rectangular nonempty parallelepiped of smaller size cut of the original heap to maximize the sum of the values of the garbage pieces in it. You have to find the optimal parallelepiped value. (Actually, if any smaller parallelepiped has value less than the original one, the farmer will leave the original parallelepiped).</span></p><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"></span></p><h2 style="MARGIN-BOTTOM: 0px; FONT-FAMILY: 'times new roman'; FONT-VARIANT: normal; WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT-STYLE: normal; LETTER-SPACING: normal; LINE-HEIGHT: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Input</span></h2><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">The first line of the input contains the number of the test cases, which is at most 15. The descriptions of the test cases follow. The first line of a test case description contains three integers<span> </span><span class="math">A</span>,<span> </span><span class="math">B</span>, and<span> </span><span class="math">C</span><span> </span>(<span class="math"><span class="number">1</span><span> </span>≤ A<span class="number">,</span><span> </span>B<span class="number">,</span><span> </span>C ≤<span> </span><span class="number">2</span><span class="number">0</span></span>). The next lines contain<span> </span><img class="mathimg" alt="$A\cdot B\cdot C$" src="http://uva.onlinejudge.org/external/107/p107552.png" width="67" height="13" /><span> </span>numbers, which are the values of garbage pieces. Each number does not exceed<span> </span><img class="mathimg" alt="$2^{31}$" src="http://uva.onlinejudge.org/external/107/p107553.png" width="21" height="16" /><span> </span>by absolute value. If we introduce coordinates in the parallelepiped such that the cell in one corner is<span> </span><span class="math"><span class="number">(</span><span class="number">1</span><span class="number">,</span><span class="number">1</span><span class="number">,</span><span class="number">1</span><span class="number">)</span></span><span> </span>and the cell in the opposite corner is<span> </span><span class="math"><span class="number">(</span>A<span class="number">,</span>B<span class="number">,</span>C<span class="number">)</span></span>, then the values are listed in the order</span></p><center style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"><img class="mathimg" alt="$$
\begin{gathered}
(1,1,1),(1,1,2),\dots,(1,1,C),\\
(1,2,1),\dots,(1,2,C),\dots,
(1,B,C),\\
(2,1,1),\dots,(2,B,C),\dots,(A,B,C).
\end{gathered}
$$" src="http://uva.onlinejudge.org/external/107/p107554.png" width="282" height="74" /></span></center><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">The test cases are separated by blank lines.</span></p><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"></span></p><h2 style="MARGIN-BOTTOM: 0px; FONT-FAMILY: 'times new roman'; FONT-VARIANT: normal; WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT-STYLE: normal; LETTER-SPACING: normal; LINE-HEIGHT: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Output</span></h2><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">For each test case in the input, output a single integer denoting the maximal value of the new garbage heap. Print a blank line between test cases.</span></p><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"></span></p><h2 style="MARGIN-BOTTOM: 0px; FONT-FAMILY: 'times new roman'; FONT-VARIANT: normal; WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT-STYLE: normal; LETTER-SPACING: normal; LINE-HEIGHT: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;">Examples</span></h2><p style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; MARGIN: 0px 0px 0pt; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px"><span style="color:#3333ff;"></span></p><table class="examples" style="WHITE-SPACE: normal; TEXT-TRANSFORM: none; WORD-SPACING: 0px; COLOR: rgb(51,51,51); FONT: 16px 'times new roman'; LETTER-SPACING: normal; TEXT-INDENT: 0px; -webkit-text-stroke-width: 0px" cellspacing="0"><tbody><tr><td class="iofiles"><span style="color:#3333ff;">Input</span></td><td class="iofiles"><span style="color:#3333ff;">Output</span></td></tr><tr><td class="examples"><pre style="WORD-WRAP: break-word; WHITE-SPACE: pre-wrap"><span style="color:#3333ff;">1
2 2 2
-1 2 0 -3 -2 -1 1 5
</span>
6
<pre class="cpp" name="code"><span style="font-size:14px;color:#3333ff;">/*
_________________________________________________________________________________________________________________
author : Grant Yaun
time : 2014.7.20
algorithm : 区间dp
thinking : 首先把三维的立方体压缩成二维的,即把a[i][j][k]变成sum1[i][j],然后用相同的思路把二维sum1[i][j]
变成一维sum2[i],然后用连续子序列求最大和算法求解即可;
notice : 把数设为long long,一开始设为int,wa了好几次;
————————————————————————————————————————————————————————————————————————————————————————————————————————————————
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<functional>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f
int x,y,z,t;
long long a[23][23][23];
long long sum1[23][23],sum2[23];
long long ans=-INF;
long long dp[23];
int main()
{
scanf("%d",&t);
while(t--){
ans=-999999999999;
scanf("%d%d%d",&x,&y,&z);
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
for(int k=0;k<z;k++)
scanf("%lld",&a[i][j][k]);
for(int j1=0;j1<y;j1++)
for(int j2=j1;j2<y;j2++)
for(int k1=0;k1<z;k1++)
for(int k2=k1;k2<z;k2++){
memset(sum1,0,sizeof(sum1));
memset(sum2,0,sizeof(sum2));
for(int d=0;d<=x;d++)
dp[d]=-INF;
for(int i=0;i<x;i++){
for(int j=j1;j<=j2;j++){
for(int k=k1;k<=k2;k++)
sum1[i][j]+=a[i][j][k];
sum2[i]+=sum1[i][j];}
}
for(int m=0;m<x;m++){
dp[m+1]=max(dp[m]+sum2[m],sum2[m]);
if(dp[m+1]>ans)
ans=dp[m+1];}}
cout<<ans<<endl;
if(t) cout<<endl;
}
return 0;
}
</span>