用生成函数求解下列递归方程 f(n)=2f(n-1)+1 n>1 f(1)=2 n=1
递归方程:
\[\begin{cases}
f(n)=2f(n-1)+1 &(n>1)&\\
f(1)=2 &(n=1)&
\end{cases}
\]
构造生成函数求解:
\[\begin{array}{lcl}
G(x)=2x^1+5x^2+11x^3+23x^4+\cdots\\\\
2x\cdot G(x)=\; +4x^2+10x^3+22x^4+\cdots\\\\
(1-2x)G(x)=2x+x^2+x^3+x^4+\cdots\\\\
\qquad\qquad\qquad =x+(x+x^2+x^3+x^4+x^5+\cdots)\\\\
\qquad\qquad\qquad=x+\frac{1}{1-x}-1=x+\frac{x}{1-x}\\\\
G(x)=\frac{x}{1-2x}+\frac{x}{(1-2x)(1-x)}\\\\
\qquad\;\, =\frac{x}{1-2x}+\frac{1}{1-2x}-\frac{1}{1-x}\\\\
\qquad\;\,=(2^0x+2^1x^2+2^2x^3+\cdots)+(2^1x^1+2^2x^2+2^3x^3+\cdots)\\\\
\qquad\qquad-(1+x+x^2+x^3+x^4+\cdots)\\\\
G(x)=(2^1+2^0-1)x+(2^2+2^1-1)x^2\cdots+(2^n+2^{n-1}-1)x^n+\cdots\\\\
\Rightarrow f(n)=2^n+2^{n-1}-1
\end{array}
\]