Есть решение
agency_ru.zip на языке Паскаль...
Код:
Program Agency;
const p=50;
type Tp=1..p;
TMp=0..p;
TArr=0..2;
TS=Set of Tp;
var A:array[Tp] of array[Tp] of TArr;
n,i,j:Tp;
Mp:TMp;
S:TS;
f:text;
Procedure Recurs(i,j:Tp;LMp:TMp;S:TS);
begin
for i:=1 to n do
if not (i in S) then
if j<n then Recurs(i,j+1,LMp+A[i,j],S+[i]) else
begin
LMp:=LMp+A[i,j];
S:=S+[i];
if LMp>Mp then Mp:=LMp;
end
end;
begin
Assign(f,'input.txt');
Reset(f);
readln(f,n);
for i:=1 to n do
for j:=1 to n do
read(f,A[i,j]);
Close(f);
Mp:=0;
S:=[];
if n>0 then Recurs(1,1,0,S);
Assign(f,'output.txt');
Rewrite(f);
write(f,Mp);
Close(f)
end.