题意:最大子矩阵.
分析:枚举矩形的上下边界,将权值纵向累加到一列上,求最大连续子序列和.复杂度O(N^3).
code:
const oo=100000000; var a,sum:array[0..110,0..110] of longint; s:array[0..110] of longint; n,i,j,k:longint; ans,max,now,maxnow:longint; function maxx(a,b:longint):longint; begin if a>b then exit(a); exit(b); end; begin readln(n); for i:=1 to n do for j:=1 to n do read(a[i,j]); for i:=1 to n do for j:=1 to n do sum[i,j]:=sum[i-1,j]+a[i,j]; max:=-oo; for i:=1 to n do for j:=i to n do begin fillchar(s,sizeof(s),0); for k:=1 to n do begin now:=sum[j,k]-sum[i-1,k]; s[k]:=maxx(s[k-1]+now,now); end; maxnow:=-oo; for k:=1 to n do if s[k]>maxnow then maxnow:=s[k]; if maxnow>max then max:=maxnow; end; writeln(max); end.