Pagini recente » Cod sursa (job #1709679) | Cod sursa (job #390495) | Cod sursa (job #1208774) | Cod sursa (job #1638596) | Cod sursa (job #11718)
Cod sursa(job #11718)
program elimin;
const
fin='elimin.in';
fout='elimin.out';
type
matr=array[1..20,1..5000] of longint;
var
a,b:matr;
smax,s:longint;
st:array[0..20] of longint;
total:longint;
ss,col:array[1..5000] of longint;
m,n,r,c,i,j,k:longint;
function num_ones(x:longint):byte;
var
num:byte;
begin
num:=0;
while x<>0 do
begin
inc(num);
x:=x and (x-1);
end;
num_ones:=num;
end;
procedure qsort(lo,hi:integer);
procedure sort(l,r:integer);
var
i,j,x:longint;
begin
i:=l;j:=r;x:=ss[(l+r) shr 1];
repeat
while ss[i]<x do
inc(i);
while ss[j]>x do
dec(j);
if i<=j then
begin
ss[j]:=ss[i] xor ss[j];
ss[i]:=ss[i] xor ss[j];
ss[j]:=ss[i] xor ss[j];
dec(j);inc(i);
end;
until i>j;
if j>l then
qsort(l,j);
if r>i then
qsort(i,r);
end;
begin
sort(lo,hi);
end;
procedure scufunda(i,n:longint);
var
p:longint;
begin
p:=i;
if i shl 1<=n then
if ss[i shl 1]>=ss[p] then
p:=i shl 1;
if i shl 1 or 1<=n then
if ss[i shl 1 or 1]>=ss[p] then
p:=i shl 1 or 1;
if p<>i then
begin
ss[p]:=ss[p] xor ss[i];
ss[i]:=ss[p] xor ss[i];
ss[p]:=ss[p] xor ss[i];
scufunda(p,n);
end;
end;
procedure hsort;
var
i:longint;
begin
for i:=n shr 1 downto 1 do
scufunda(i,n);
for i:=n downto 2 do
begin
ss[1]:=ss[1] xor ss[i];
ss[i]:=ss[1] xor ss[i];
ss[1]:=ss[1] xor ss[i];
scufunda(1,i-1);
end;
end;
function sum:longint;
var
i,j:longint;
s:longint;
begin
s:=total;
for i:=1 to n do
ss[i]:=col[i];
for i:=1 to n do
for j:=1 to r do
begin
dec(ss[i],a[st[j],i]);
dec(s,a[st[j],i]);
end;
hsort;
for i:=1 to c do
dec(s,ss[i]);
sum:=s;
end;
procedure back;
var
i:longint;
x:longint;
ind,poz:byte;
begin
for i:=0 to 1 shl m-1 do
begin
if num_ones(i)=r then
begin
x:=i;
ind:=0;poz:=m+1;
while (x<>0) do
begin
dec(poz);
if (x and 1=1) then
begin
inc(ind);
st[ind]:=poz;
end;
x:=x shr 1;
end;
x:=sum;
if x>smax then
smax:=x;
end;
end;
end;
begin
assign(input,fin);
reset(input);
readln(m,n,r,c);
st[0]:=0;
if m>15 then
begin
for i:=1 to m do
for j:=1 to n do
read(a[j,i]);
m:=m xor n;
n:=m xor n;
m:=m xor n;
r:=r xor c;
c:=r xor c;
r:=r xor c;
end
else
begin
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
end;
total:=0;
for j:=1 to n do
for i:=1 to m do
begin
inc(total,a[i,j]);
inc(col[j],a[i,j]);
end;
close(input);
assign(output,fout);
rewrite(output);
smax:=0;
back;
writeln(smax);
close(output);
end.