The strategy suggested in Geoffry Irving's answer of betting the maximum amount each time is correct, but the argument given is incomplete. The expected final amount, conditional on the outcomes of the first $n$ coin flips, is a linear function of the amount we have after the $n$th coin flip, but this linear function is not independent of the result of the $n$th coin flip, so it's not clear that it's correct to bet if the $n$th coin flip has a probability $>1/2$ of coming up heads and incorrect if the $n$th coin flip has a probability $<1/2$ of coming up heads.

In fact, this logic suggests we should be indifferent to whether we bet or not on the first coin flip, but this is not correct: Say $N=2$, the strategy of betting the maximum amount each time gives an expected return of $\\\$4/3$ while the strategy of not betting on the first coin flip, and then betting the maximum amount if the first coin flip comes up heads, gives an expected return of only $\\\$7/6$.

Betting the maximum amount each time is the unique optimal strategy for the following reason: There are $2^N$ possible sequences of heads and tails. If the coin were fair, each of those outcomes would occur with probability $2^{-N}$ and betting would be a martingale so the sum over all sequences of the money left in each sequence would be $2^N$. Thus, the maximum expectation achieved is $2^N$ times the probability of the most probable outcome, and this is achieved if and only if the strategy leaves us with $\\\$0$ on every outcome except the most probable.

A sequences of $k$ heads and $N-k$ tails has a probability $\frac{1}{ (N+1) \binom{N}{k}}$ which is maximized if and only if $k=0$ or $k=N$. The strategy of always bet everything gives $\\\$0$ except if $k=N$, so it indeed achieves the maximum, and no other strategy achieves the maximum since we must lose on every sequence with exactly one tail, and thus must bet the maximum after every number of heads.

An interesting question is, if you start playing the game after seeing the coin produce a certain number of heads and a certain number of tails, when you should bet. It may be optimal in some cases to bet with a probability of heads slightly less than $1/2$. Certainly this is true if we allow a non-integer number of heads so far (more sensibly, if we draw $p$ from a beta distribution instead of a uniform distribution): If one varies the parameters slightly from the starting value, the optimal strategy stays the same.

2more comments