Pagini recente » Cod sursa (job #3256651) | Cod sursa (job #2570456) | Cod sursa (job #2699087) | Cod sursa (job #1615636) | Cod sursa (job #714147)
Cod sursa(job #714147)
type matrix=array[1..16,1..16] of longint;tomb=array[1..2,1..16] of integer;
var i,j,k,m,n,l,h:integer;van,jo:boolean;t:matrix;v:tomb;f,g:text;s,max:longint;
procedure kovetkezo(k:integer;var van:boolean);
begin
van:=false;
if k=n then
l:=2;
if (v[l,k]<1) and (k<m) and (k<n) then
begin
van:=true;
v[l,k]:=v[l,k]+1;
end;
end;
procedure ellenoriz(var jo:boolean);
begin
s:=0;
for i:=1 to m do
for j:=1 to n do
begin
s:=s+t[i,j];
if v[1,i]=1 then
s:=s-2*t[i,j]
else
if v[2,j]=1 then
s:=s-2*t[i,j];
end;
if s>max then
begin
jo:= true;
max:=s;
end;
end;
BEGIN
assign(f,'flip.in');assign(g,'flip.out');
reset(f);read(f,m,n);k:=1;l:=1;v[l,k]:=-1;
for i:=1 to m do
for j:=1 to n do
read(f,t[i,j]);
close(f);
while k>0 do
begin
repeat
kovetkezo(k,van);
if van then
ellenoriz(jo);
until ((van) and (jo)) or (not van);
if not van then
k:=k-1
else
begin
k:=k+1;
v[l,k]:=-1;
end;
end;
rewrite(g);write(g,max);close(g);
end.