function step5(A,B,rows,cols,Lx,Ly,Ns,S,T)
for i=S
for j=1:cols
if B(i,j)==1
if any(Ns==j)==0
Ns=[Ns,j];
end
end
end
end
a=inf;
if length(Ns)==length(T)
for i=S
for j=1:cols
if any(j==T)==0
b=Lx(i)+Ly(j)-A(i,j);
if a>b
a=b;
end
end
end
end
for i=S
Lx(i)=Lx(i)-a;
end
for j=T
Ly(j)=Ly(j)+a;
end
step2(A,Lx,Ly);%%%%这个地方要跳到step2,如果跳到了step2,下面的都不会运行
else %%%%下面是寻路过程,也就是step6
for i=1:length(Ns)
p=0;
for j=T
if Ns(i)==j
p=1;
end
end
if p==0
y=Ns(i);
T=[T,y];
break;
end
end
p=0;
for i=1:rows
if B(i,y)==2
S=[S,i];
p=1;
break;
end
end
if p==1
step5(A,B,rows,cols,Lx,Ly,Ns,S,T);
else %%%%%扩路
for i=1:rows
if B(i,y)==0
p=i;
break;
end
end
k=[];
extendable_path(A,B,y,p,k,Lx,Ly);
end
end
end