import math,sys
xy,dp=((0,10),(0,20),(8,26),(15,26),(27,21),(22,12),(10,0),),{}
def C(i,j):
if dp.get((i,j),None):return dp[(i,j)]
if 3>=j:#C(i,j)=0
dp[(i,j)] = 0
else:
dp[(i,j)] = sys.maxsize
for k in range(i+1, i+j-1):
dp[(i,j)] = min(C(i,k-i+1)+C(k,i+j-k)+D(i,k)+D(k,i+j-1),dp[(i,j)])
return dp[(i,j)]
def D(i,j):#i,j相邻时D(i,j)=0
return 0 if i+1==j else math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
C(0,7)
75.43073157009471