从我如何才能自动生成这个动态规划图?,Jubobs 帮助开发了一个foreach
绘制路径的方案。我想知道 LaTeX 是否可以通过实施动态规划来找到最便宜的路径。
\documentclass{article}
\usepackage{tikz}
\newcounter{rowcount}
\newcounter{columncount}
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{scope}[rotate=-45]
% rows
\foreach[count=\y from 0] \W in
{{7,8,6},{8,8,8},{6,9,7},{7,8,10}} % row-wise weights
{
\stepcounter{rowcount}
\foreach \w [count=\x, remember=\x as \lastx (initially 0)] in \W
\draw (\lastx,\y) -- (\x,\y)
node[above,pos=0.5] {\w};
}
% columns
\foreach[count=\x from 0] \W in
{{5,6,10},{7,10,5},{10,5,6},{7,9,11}} % column-wise weights
{
\stepcounter{columncount}
\foreach \w [count=\y, remember=\y as \lasty (initially 0)] in \W
\draw (\x,\lasty) -- (\x,\y)
node[above,pos=0.5] {\w};
}
\fill (0,0) circle (0.1em) node[below left] {A};
\fill ({\value{columncount}-1},{\value{rowcount}-1}) circle (0.1em) node[below right] {B};
\end{scope}
\end{tikzpicture}
\end{document}
- LaTeX 有这个能力吗?
- 如果确实如此,那么这样的事情是如何做到的?