I have to count the number of partitions of the set $\{1,\ldots,n\}$ under the constraint that for each $i$, the elements $i$ and $i+1$ are in different parts.
The my idea is:
We have two situation when it comes to $1,2,3 \to \{1\}\{2\}\{3\}$ or $\{1,3\}\{2\}\{\text{ one of }\{4,5,\ldots n\}\}$. For every element I choose part (there are two possibilities) Thus, $$2^{n-3} + (n-3)2^{n-4} $$

I call a partition of $\{1,2,\dots,n\}$ into exactly $k$ sets with the restrictions on neighbours mentioned in the question an "$(n,k)$ partition". Let $f(n,k)$ be the number of $(n,k)$ partitions. We can obtain a recursive formula as follows:
Consider an $(n,k)$ partition. Remove $n$ from the partition. Now we're left either with an $(n-1,k)$ partition (if $n$ was not in a singleton set) or with an $(n-1,k-1)$ partition (if $n$ was in a singleton set). Therefore, each $(n,k)$ partition can be constructed from an $(n-1,k)$ partition or from an $(n,k-1)$ partition. Moreover, the construction is always unique.
There are $k-1$ ways to extend an $(n-1,k)$ partition to an $(n,k)$ partition: $n$ can be added to any of the sets that don't have $n-1$. There is only $1$ way to extend an $(n-1,k-1)$ partition to an $(n,k)$ partition: add a new set $\{n\}$.
Now we get the recursion formula $$ f(n,k) = (k-1) f(n-1,k) + f(n-1,k-1). $$ The initial conditions are, for example, $f(1,1)=1$, $f(n,1)=0$ for all $n\geq2$, and $f(n,k)=0$ if $n<k$.
The answer to your question is now $\sum_{k=1}^{n} f(n,k)$.
Unfortunately I haven't figured out how to solve this recursive formula.
Edit 1: Thanks to xawey's comment, I looked more closely at the numbers given by this recursive formula. The recursive formula is similar to the recursive formula of Stirling numbers of second kind. This gives $f(n,k)=S(n-1,k-1)$, where $S(a,b)$ is the number of ways to partition a set of size $a$ into exactly $b$ sets. This implies that $\sum_{k=1}^{n} f(n,k) = B_{n-1}$, the number of ways to partition a set of size $n-1$. There must be a simple combinatorial interpretation.