⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1076.pas

📁 uralcode
💻 PAS
字号:
program ural1076;
const
  maxn=150;
var
  w:array[1..maxn,1..maxn]of byte;
  link,lx,ly:array[1..maxn]of byte;{link[i]=j means xj matches yi}
  x,y:array[1..maxn]of boolean;{True if the vertex is in the interlaced tree}
  n,i,j:byte;
  total:longint;
function find(v:byte):boolean;
  var
    i:byte;
  begin
    x[v]:=true;
    for i:=1 to n do
      if not y[i] and (lx[v]+ly[i]=w[v,i]) then begin
        y[i]:=true;
        if (link[i]=0) or find(link[i]) then begin
          find:=true;link[i]:=v;exit;
        end;
      end;
    find:=false;
  end;
procedure KM;
  var
    i,j,k,d:byte;
  begin
    fillchar(lx,sizeof(lx),0);fillchar(ly,sizeof(ly),0);
    for i:=1 to n do
      for j:=1 to n do
        if w[i,j]>lx[i] then lx[i]:=w[i,j];
    for k:=1 to n do
      repeat
        fillchar(x,sizeof(x),0);fillchar(y,sizeof(y),0);
        if find(k) then break;
        d:=255;
        for i:=1 to n do
          if x[i] then
            for j:=1 to n do
              if not y[j] then
                if lx[i]+ly[j]-w[i,j]<d then
                  d:=lx[i]+ly[j]-w[i,j];
        for i:=1 to n do
          if x[i] then dec(lx[i],d);
        for i:=1 to n do
          if y[i] then inc(ly[i],d);
      until false;
  end;
begin
  readln(n);
  total:=0;
  for i:=1 to n do
    for j:=1 to n do begin
      read(w[i,j]);
      inc(total,w[i,j]);
    end;

  KM;

  for i:=1 to n do
    dec(total,w[link[i],i]);
  writeln(total);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -