Finding the longest repeating subsequence
Here is a dynamic programming solution.

Suppose that the input string is $x_1\ldots x_n$. Create a table $T$ whose rows and columns are indexed by $0,\ldots,n$ (where $n$ is the length of the string), populated by the rule
$$
 T[i,j] =
\begin{cases}
0 &amp; \text{if $i = 0$ or $j = 0$}, \\
T[i-1,j-1] + 1 &amp; \text{if $x_i = x_j$ and $i \neq j$}, \\
\max(T[i-1,j],T[i,j-1]) &amp; \text{otherwise}.
\end{cases}
$$
The answer is $T[n,n]$.