d165.
八、草场普查
--
NOI冬令营
| From: [60.246.227.68] |
發表日期
:
2013-02-10 17:06
var
i,j,k,s,m,l,n,max,d,t:longint;
a:array [0..1000,0..1000] of longint;
b:array [1..100000,1..2]of longint;
procedure search(x,y:longint);
var
i,j:longint;
begin
if a[x,y]<>0 then
begin
if t=0 then
s:=s+1;
t:=t+a[x,y];
a[x,y]:=0;
if a[x-1,y]<>0 then search(x-1,y);
if a[x+1,y]<>0 then search(x+1,y);
if a[x,y+1]<>0 then search(x,y+1);
if a[x,y-1]<>0 then search(x,y-1);
if t>max then
max:=t;
end;
end;
begin
while not eof do
begin
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
l:=0;
max:=0;
s:=0;
readln(n,m);
for i:=1 to n do
for j:=1 to m do
begin
readln(a[i,j]);
if a[i,j]<>0 then
begin
l:=l+1;
b[l,1]:=i;
b[l,2]:=j;
end;
end;
for i:=1 to l do
begin
t:=0;
search(b[i,1],b[i,2]);
end;
writeln(s);
writeln(max);
end.