If one is interested only in finding the minimal cost, then transfer-matrix method over the tropical semiring $R$ will do the job. That isNamely, consider the graphline digraph $G:=L(D)$ and its weighted adjacency matrix over $R$, raise it to the power $l-1$$l-2$, and "sum up" (in $R$) the entries corresponding to the pairs of indicespossible start and end edges in $G$ (corresponding to pairs of vertices from $S\times T$ in $D$) multiplied by their costs.