class Heap_Point: def __init__(self,x,d): self.d=d self.x=x def __str__(self): return "(point:{}, dist:{})".format(self.x,self.d) def __repr__(self): return str(self) def __lt__(self,other): return self.dd+F: T[x+1][y][k]=d+F heappush(Q,Heap_Point((x+1,y,k),d+F)) if yd+F: T[x][y+1][k]=d+F heappush(Q,Heap_Point((x,y+1,k),d+F)) for i,q in enumerate(P[k+1:],k+1): a,b,c=q if 0<=x+a<=Gx and 0<=y+b<=Gy and T[x+a][y+b][i]>d+c: T[x+a][y+b][i]=d+c heappush(Q,Heap_Point((x+a,y+b,i),d+c)) print(min(T[Gx][Gy]))