40. Let $h_{m}^{\prime}(n)$ denote the number of ways to color a $2 \times n$ chessboard using $m$ colors such that adjacent cells have different colors and each color is used at least once. Find the counting formula for $h_{m}^{\prime}(n)$.
40. $h_{m}^{\prime}(n)=\sum_{k=2}^{m}(-1)^{m-k}\binom{m}{k}\left(k^{2}-3 k+3\right)^{n-1} k(k-1)$.