传送门
水题。
首先暴力求出所有k*k矩形的和,时间N^2
然后对每个点用前缀和维护出左上,左下,右上,右下的最大矩阵,再对每一行(列)维护以这一行(列)为底边的最大矩阵,然后枚举分割线暴力求解,
分割线只可能有6种情况,
暴力水过。
uses math;
var
a,b,c,d,f:array [0..2505,0..2505] of longint;
n,m,k,i,j,ans:longint;
begin
read(n,m,k);
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
for i:=1 to n do
for j:=1 to m do a[i,j]:=a[i,j]+a[i,j-1];
for i:=1 to n do
for j:=1 to m do a[i,j]:=a[i,j]+a[i-1,j];
n:=n-k+1; m:=m-k+1;
for i:=1 to n do
for j:=1 to m do f[i,j]:=a[i+k-1,j+k-1]-a[i-1,j+k-1]-a[i+k-1,j-1]+a[i-1,j-1];
fillchar(a,sizeof(a),0);
for i:=1 to n do
for j:=1 to m do a[i,j]:=max(f[i,j],max(a[i,j-1],a[i-1,j]));
for i:=1 to n do
for j:=m downto 1 do b[i,j]:=max(f[i,j],max(b[i,j+1],b[i-1,j]));
for i:=n downto 1 do
for j:=1 to m do c[i,j]:=max(f[i,j],max(c[i,j-1],c[i+1,j]));
for i:=n downto 1 do
for j:=m downto 1 do d[i,j]:=max(f[i,j],max(d[i,j+1],d[i+1,j]));
ans:=0;
for i:=k+1 to n do
for j:=k+1 to m do ans:=max(ans,max(a[i-k,j-k]+b[i-k,j]+d[i,1],b[i-k,1]+c[i,j-k]+d[i,j]));
for i:=k+1 to n do
for j:=k+1 to m do ans:=max(ans,max(c[1,j-k]+b[i-k,j]+d[i,j],d[1,j]+a[i-k,j-k]+c[i,j-k]));
for i:=1 to n do
for j:=k+1 to m-k do ans:=max(ans,a[n,j-k]+f[i,j]+d[1,j+k]);
for i:=k+1 to n-k do
for j:=1 to m do ans:=max(ans,a[i-k,m]+f[i,j]+d[i+k,1]);
write(ans);
end.