Pagini recente » Cod sursa (job #2105713) | Cod sursa (job #1591929) | Cod sursa (job #305069) | Cod sursa (job #1714674) | Cod sursa (job #282361)
Cod sursa(job #282361)
program suma;
const fin = 'flip.in';
fout = 'flip.out';
type matrice = array [1..16,1..16] of longint;
type stiva = array [1..16] of longint;
var i,j,k,n,m:byte;
a:array [1..16,1..16] of longint;
s:longint;
st,rez:stiva;
procedure init;
begin
st[k]:=3;
end;
function exista:boolean;
begin
exista:=false;
if (k<=n) and (st[k]>-1) then
begin
dec(st[k],2);
exista:=true;
end;
end;
function solutie:boolean;
begin
solutie:=k=n;
end;
procedure prelucrare(b:matrice);
var t:longint;
begin
fillchar(rez,sizeof(rez),0);
t:=0;
for i:=1 to k do
begin
for j:=1 to m do
begin
b[i,j]:=b[i,j]*st[i];
inc(rez[j],b[i,j]);
end;
end;
for i:=1 to m do
inc(t,abs(rez[i]));
if t>s then
s:=t;
end;
procedure back;
begin
k:=1;
init;
while k>0 do
if exista then
begin
if solutie then
prelucrare(a)
else
begin
inc(k);
init;
end;
end
else
dec(k);
end;
begin
{citire}
assign(input,fin);
assign(output,fout);
reset(input);
s:=0;
read(n,m);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
back;
{tipar}
rewrite(output);
write(s);
close(input);
close(output);
end.