Combinatorial PGF for counting problems

The question uses a multivariate or univariate generating function to encode a combinatorial counting problem such as permutations, derangements, or partitions, and relates it to probabilistic quantities.

grandes-ecoles 2017 QIVC View
We are given a probability space $( \Omega , \mathcal { A } , \mathbb { P } )$. We set for every integer $n \geqslant 0$, $B _ { n } = \sum _ { k = 0 } ^ { n } S ( n , k )$ where $S(n,k)$ is the number of partitions of $\llbracket 1,n \rrbracket$ into $k$ parts. Let $m$ be a strictly positive integer, and $\mathbb { E } \left( Y ^ { m } \right) = \sum _ { n = 0 } ^ { \infty } n ^ { m } \mathbb { P } ( Y = n )$.
We assume in this question that $Y$ follows the Poisson distribution with parameter 1.
IV.C.1) Show that for all $n \in \mathbb { N } , B _ { n } = \mathbb { E } \left( Y ^ { n } \right)$.
IV.C.2) Deduce that for every polynomial $Q ( X )$ with integer coefficients, the series $\sum _ { n = 0 } ^ { + \infty } \frac { Q ( n ) } { n ! }$ is convergent and its sum is of the form $N e$, where $N$ is an integer.
todai-math 2023 Q3 View
Let us randomly place circle stones $\bigcirc$ and square stones $\square$ one by one in a line from left to right. The circle and square stones are placed with probability $1 - q$ and $q$, respectively, according to the independent and identical distribution, where $0 < q < 1$. The placement stops right after $M$ square stones are placed in a row, where $M$ is a positive integer. We show examples of the lines for $M = 4$ as follows.
Let $L$ be a random variable which represents the number of the stones after stopping the placement. For the case of the lines shown above, $L = 5$ and $L = 9$ for lines 1 and 2, respectively.
Here, we consider intermediate states during the placement. Let $k$ be a non-negative integer and let $C_k$ be a state of a line where there are $k$ square stones in a row from the right end. Since we are considering the case of $M = 4$, lines 3 and 4 are not stopped yet. Line 3 is in state $C_2$ since there are 2 square stones in a row from the right end. Line 4 is in state $C_0$ since there is no square stone at the right end. Let $a_{kn}$ be the probability that the stopping condition is met after placing $n$ stones starting from state $C_k$, where $n$ is a non-negative integer. We define the following generating function $A_k(t)$ for $a_{kn}$.
$$A_k(t) = \sum_{n=0}^{\infty} t^n a_{kn}$$
Answer the following questions.
(1) Calculate the mean and variance of $L$ for $M = 1$.
(2) Obtain the recurrence relation that $A_k(t)$ satisfies.
(3) Obtain $A_k(t)$ as a function of $q, M, t$, and $k$.
(4) Calculate the mean of $L$.