我们希望在课堂笔记中处理子问题。在某些情况下,需要提出一个特定的子问题(及其答案),但在提出子问题之前,我们希望展示问题的表述。在下面的例子中,当其中一个子问题被“调用”时,需要出现“解决以下递归。”
\documentclass{文章}
\usepackage[answers,draft]{probsoln}
%\usepackage[noanswers,final]{probsoln}
\usepackage{enumitem}
\usepackage{amsmath,amsfonts}
\makeatletter
\newcommand{\amdlabel}[1]{% Avoiding Multiply defined labels
\@ifundefined{c@#1}{ \newcounter{#1}\setcounter{#1}{0}}{}%
\ifthenelse{\value{#1} > 0}{}{\label{#1}\addtocounter{#1}{1}}%
} \makeatother
\newcommand{\Useproblem}[1]{
\item \amdlabel{#1} \useproblem{#1}
}
\newcommand{\Exercise}[1]{\paragraph*{Ex.~\ref{#1}}\useproblem{#1}}
\newcommand*\fixitem[2]{\item[]
\refstepcounter{enumi}\hskip-\labelwidth\hskip-\labelsep
\textbf{#1 \ref{#2}} }
\newcommand{\ExerciseT}[1] %
{\begin{enumerate}%
\fixitem{\textbf{Ex.}}{#1} \useproblem{#1}%
\end{enumerate}%
}
\newcommand{\ExerciseTS}[2] %
{\begin{enumerate}%
\fixitem{\textbf{Ex.}}{#2}%
\useproblem{#2}%
\end{enumerate}%
}
\newproblem{ex:nHLR:2}{
\begin{equation*}
f(n) = \begin{cases} n, & \text{ if } n < 1, \\
2f(n-1) + n, & \text{ if } n \geq 1. \end{cases}
\end{equation*}
}{
\begin{equation*}
f(n) = c_{1,0} + c_{1,1} n + c_{2,0} 2^{n},
\end{equation*}
\begin{equation*}
f(n) = 2^{n+1} - n - 2,
\end{equation*}
for all $n \in \mathbb{N}$.
}
\newproblem{ex:nHLR:n2}{
\begin{equation*}
f(n) = 2 f(n-1) + n^2
\end{equation*}
for all $n \in \mathbb{N}$.
}{
\begin{equation*}
f(n) = c_{1,0} + c_{1,1} n + c_{1,2} n^2 + c_{2,0} 2^{n},
\end{equation*}
for all $n \in \mathbb{N}$.
\begin{equation*}
f(n) = ( 6 + f(0) ) 2^{n} -6 -4n -n^{2} \\
\end{equation*}
for all $n \in \mathbb{N}$.
}
\begin{defproblem}{ex:nHLR}
Solve the following recurrences.
\begin{enumerate}
\Useproblem{ex:nHLR:2}
\Useproblem{ex:nHLR:n2}
\end{enumerate}
\end{defproblem}
\begin{document}
\section{Classroom Notes 10}
At a specific point, we wish to present only a subquestion, i.e., \ExerciseTS{ex:nHLR}{ex:nHLR:n2} with the \textbf{main enunciate} of the exercise.
\vspace{24pt}
We also might wish, during the lecture, to present an entire exercise, i.e., \ExerciseT{ex:nHLR}
\section*{Exercises}
\begin{enumerate}
\Useproblem{ex:nHLR}
\end{enumerate}
\end{document}