Garbage Heap
来源:互联网 发布:kmeans聚类算法代码 编辑:程序博客网 时间:2024/05/14 02:16
Time limit: ? seconds
Farmer John has a heap of garbage formed in a rectangular parallelepiped.
It consists of 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).
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).
Input
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 A, B, and C (1 ≤ A, B, C ≤ 20). The next lines contain numbers, which are the values of garbage pieces. Each number does not exceed by absolute value. If we introduce coordinates in the parallelepiped such that the cell in one corner is (1,1,1) and the cell in the opposite corner is (A,B,C), then the values are listed in the order
The test cases are separated by blank lines.
Output
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.
Examples
InputOutput12 2 2-1 2 0 -3 -2 -1 1 5
6这道题是Distant Galaxy的延伸,变成了三维的图形,同时在求废料块的价值时用到了Substance里的“前缀和”以及Open Credit System的维护最大值。代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define FOR(i,t,n) for(int i=(t);i<=(n);i++) //宏定义简化代码(Image Is Everything)const long long int INF=1LL<<60; //注意极大的数如何表示long long int s[25][25][25];int main(){int T;cin>>T;while(T--){memset(s,0,sizeof(s));int A,B,C;cin>>A>>B>>C;FOR(i,1,A) FOR(j,1,B) FOR(k,1,C){long long int x;scanf("%lld",&x);s[i][j][k]=x+s[i-1][j][k]+s[i][j-1][k]-s[i-1][j-1][k]+s[i][j][k-1]-s[i-1][j][k-1]-s[i][j-1][k-1]+s[i-1][j-1][k-1]; }long long int ans=-INF;FOR(i,1,C) FOR(i1,i,C){FOR(j,1,B) FOR(j1,j,B){long long int l=0;FOR(k,1,A){long long int g;g=s[k][j1][i1]-s[k][j1][i-1]-(s[k][j-1][i1]-s[k][j-1][i-1]);ans=max(ans,g-l);l=min(l,g);}}}cout<<ans<<endl;if(T) cout<<endl; //特别注意}return 0;}还是要特别注意以下输出数据的格式
- Garbage Heap
- Garbage Heap
- UVA 10755 Garbage Heap
- UVa:10755 Garbage Heap
- UVA 10755 Garbage Heap
- uva10755 - Garbage Heap
- 10755 - Garbage Heap
- UVA - 10755 Garbage Heap
- uva10755 - Garbage Heap
- UVA 10755 Garbage Heap
- uva10755 Garbage Heap
- 【UVA10755】Garbage Heap
- uva 10755 - Garbage Heap 杂
- uva 10755 - Garbage Heap(暴力+优化)
- uva10755 - Garbage Heap 找最大子立方体
- 【UVa】10755 Garbage Heap 三维前缀和
- UVA - 10755 Garbage Heap(最大子矩阵)
- uva10755 - Garbage Heap (最大子立方体)
- MFC之系统托盘实现
- 动漫推荐之百变之星
- c#网络通信框架networkcomms内核解析之四 心跳检测
- c++标准库——pair和tuple
- c#网络通信框架networkcomms内核解析之五 数据监听
- Garbage Heap
- c#网络通信框架networkcomms内核解析之六 处理接收到的二进制数据
- 依赖注入(DI)和Ninject
- c#网络通信框架networkcomms内核解析之七 数据包创建器(PacketBuilder)
- c#网络通信框架networkcomms内核解析之八 数据包的核心处理器
- kali Linux之BeFF安装与集成Metasploit
- c#网络通信框架networkcomms内核解析之九 自定义处理方法的运行机制
- c#网络通信框架networkcomms内核解析之十 支持优先级的自定义线程池
- HDU1251 统计难题【字典树】