clear
clc
A=[0 15 5 10 5 20;0 30 30 20 5 10;0 85 162 26 140 110];
rong=300;
m=6; c=zeros(6,6);
for i=1:m
for j=1:m c(i,j)=sqrt((A(1,i)-A(1,j))A2+(A(2,i)-
A(2,j)F2);
end end
p=zeros(6,6);
for i=2:(m-1)
for j=(i+1):m p(i,j)=c(1,i)+c(1,j)-c(i,j);
end end
s=p(:); [hs,wz]=sort(s,1,'descend');
for i=1:(m
A
2) [x,y]=ind2sub(size(p),wz(i)); if
A(3,x)+A(3,y)<=rong solut=[x,y]; n(1)=2;
zhuang(1)=A(3,x)+A(3,y);
ii=i; break else
continue
end
end
for rr=(ii+1):(mA2) [x,y]=ind2sub(size(p),wz(rr)) if
hs(rr)==0
break end
[xa,ya]=find(x==solut)
[xb,yb]=find(y==solut)
[sa,sb]=size(solut)
if isempty(xa)==0 && isempty(xb)==0 if xa==xb
continue
end
if n(xa)~=2
if 1
if n(xb)~=2
if 1
zh1=zhuang(xa)
zh2=zhuang(xb)
if zhuang(xa)+zhuang(xb)<=rong
if ya==1&&yb==1
newm=[solut(xb,n(xb):-1:1) solut(xa,1:n(xa))]
elseif ya==1&&yb==n(xb)
newm=[solut(xb,1:n(xb)) solut(xa,1:n(xa))]