记录编号 47582 评测结果 AAAAAAAAAA
题目名称 [Matrix模拟赛] 吃西瓜 最终得分 100
用户昵称 Gravatarfeng 是否通过 通过
代码语言 C++ 运行时间 3.133 s
提交时间 2012-11-02 09:40:32 内存使用 53.41 MiB
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
int n,m,i,j,k,l,h,ans,tmp,x,minn;
int a[60][60][60];
int f[60][60][60][60];
int main()
{
	freopen("matrix.in","r",stdin);
	freopen("matrix.out","w",stdout);
	scanf("%d%d%d",&h,&n,&m);
	for (int k=1;k<=h;k++){
		for (int i=1;i<=n;i++) 
		{ 
			for (int j=1;j<=m;j++) 
			{ 
				scanf("%d",&x);
				a[i][j][k]=a[i-1][j][k]+a[i][j-1][k]+a[i][j][k-1]-a[i-1][j-1][k]-a[i][j-1][k-1]-a[i-1][j][k-1]+a[i-1][j-1][k-1]+x; 
				x=0;
			} 
		}
	}
	
	for (int i=1;i<=n;i++)
		for (int j=i;j<=n;j++)
			for (int k=1;k<=m;k++)
				for (int l=k;l<=m;l++){
					int minn=0;
					f[i][j][k][l]=0;
					for (int x=1;x<=h;x++){
						tmp=a[j][l][x]-a[i-1][l][x]-a[j][k-1][x]+a[i-1][k-1][x];
						if (tmp-minn>f[i][j][k][l])
							f[i][j][k][l]=tmp-minn;
						if (tmp<minn)
							minn=tmp;
					}
					if (f[i][j][k][l]>ans) ans=f[i][j][k][l];
				}
	printf("%d",ans);
	return 0;
}