注意sum的改变
共2^20种情况,应该也可以用位运算
Program P2531;
Var
n,i,j:longint;
a:array[1..20,1..20] of longint;
b:array[1..20] of boolean;
ans:longint;
procedure dfs(k,sum:longint);
var
i,j,sum2:longint;
begin
b[k]:=true;
sum2:=sum;
for i:=1 to n do
if b[i] then dec(sum2,a[i,k])
else inc(sum2,a[i,k]);
if (ans<sum2) then ans:=sum2;
for i:=k+1 to n do
begin
dfs(i,sum2);
end;
b[k]:=false;
end;
begin
ans:=-100000;
read(n);
fillchar(b,sizeof(b),false);
for i:=1 to n do
for j:=1 to n do
read(a[i,j]);
dfs(1,0);
writeln(ans);
end.