答案1
感谢 MS-SPO 指出我设法得到的包,结合带圈的数字即可pseudo
找到我所寻找的内容。(使用,我们也可以制作方框)tikz
mdframed
tabular
\pseudoset{label=\protect\circled{\arabic*}, line-height=1.2, ref}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
\begin{mdframed}
{\hspace{0.25em} \Large Dynamic Programming Knapsack Algorithm} \\[0.5em]
\begin{tabular}{p{3em} p{30em}}
\textit{Input:} & Nonnegative integers $n, c_1,\dots,c_n,w_1,\dots, w_n$ and $W$. \\[0.5em]
\textit{Output:} & A subset $S\subseteq \{1, \dots, n\}$ such that $\sum_{j\in S} w_j \leq W$ and $\sum_{j\in S} c_j$ is maximum.
\end{tabular}
\end{mdframed}
\begin{pseudo}
Let $C$ be any upper bound on the value of the optimum solution, e.g. \\*& \; $C:=\sum_{j=1}^n c_j$. \\
Set $x(0,0):=0$ and $x(0,k):=\infty$ for $k=1,\dots, C$. \\
\kw{For} $j:=1$ \kw{to} $n$: \\+*&
\kw{For} $k:=0$ \kw{to} $C$: \\+*&
Set $s(j, k):=0$ and $x(j, k):=x(j-1, k)$ . \\-*&
\kw{For} $k:=c_j$ \kw{to} $C$: \\+*&
\kw{If} $x(j-1, k-c_j) + w_j \leq \min\{W, x(j,k)\}$ \kfw{then}: \\+*&
Set $x(j,k) := x(j-1, k-c_j) + w_j$ and $s(j, k):=1$. \\---
Let $k=\max\{i\in\{0,\dots, C\}:x(n,i) < \infty\}$. Set $S:=\emptyset$. \\*&
\kw{For} $j:=n$ \kw{down to} $1$: \\+*&
\kw{If} $s(j, k)=1$ \kw{then} set $S:= S\cup \{j\}$ and $k:=k-c_j$.
\end{pseudo}