Cod sursa(job #14147)
Utilizator | Data | 8 februarie 2007 13:12:07 | |
---|---|---|---|
Problema | Elimin | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 3.15 kb |
var s,bin,st:array[0..2000]of longint;
v:array[0..800,0..7500]of longint;
x:array[0..2000]of longint;
i,j,n,m,r,c,stot,max,aux:longint;
procedure back(k,no:longint);
var i,j,ss,min,nr:longint;
ok:boolean;
begin
if k=no then
begin
nr:=0;
for i:=1 to no do
if st[i]=1 then
begin
inc(nr);
s[nr]:=i;
end;
if nr=r then
begin
ss:=stot;
for i:=1 to n do
x[i]:=v[0,i];
for i:=1 to nr do
for j:=1 to n do
dec(x[j],v[s[i],j]);
for i:=1 to nr do
ss:=ss-v[s[i],0];
for i:=1 to c do
begin
min:=1;
for j:=2 to n do
if x[j]<x[min] then
min:=j;
ss:=ss-x[min];
x[min]:=maxint;
end;
if ss>max then
max:=ss;
end
else if nr=c then
begin
ss:=stot;
for i:=1 to m do
x[i]:=v[i,0];
for i:=1 to nr do
for j:=1 to m do
dec(x[j],v[j,s[i]]);
for i:=1 to nr do
ss:=ss-v[0,s[i]];
for i:=1 to r do
begin
min:=1;
for j:=2 to m do
if x[j]<x[min] then
min:=j;
ss:=ss-x[min];
x[min]:=maxint;
end;
if ss>max then
max:=ss;
end;
end
else
for i:=0 to 1 do
begin
st[k+1]:=i;
back(k+1,no);
end;
end;
begin
assign(input,'elimin.in');reset(input);
assign(output,'elimin.out');rewrite(output);
readln(m,n,r,c);
if n<m then
begin
aux:=n;
n:=m;
m:=aux;
aux:=r;
r:=c;
c:=aux;
for i:=1 to n do
for j:=1 to m do
begin
read(v[j,i]);
inc(v[j,0],v[j,i]);
stot:=stot+v[j,i];
end;
for i:=1 to m do
for j:=1 to n do
inc(v[0,j],v[i,j]);
end
else begin
for i:=1 to m do
for j:=1 to n do
begin
read(v[i,j]);
inc(v[i,0],v[i,j]);
stot:=stot+v[i,j];
end;
for i:=1 to n do
for j:=1 to m do
inc(v[0,i],v[j,i]);
end;
if n<m then
back(0,n)
else
back(0,m);
writeln(max);
close(input);close(output);
end.