I thought this was relatively harder so wanted to analyse this as well.
The task goes as follows: The inhabitants of an island are divided into three tribes: Bears, Hunters, and Ninjas. They are very hostile, and whenever two members of different tribes meet, the stronger one always eliminates the weaker one. It is known that a bear is stronger than a ninja, a ninja is stronger than a hunter, a hunter is stronger than a bear. The hostility goes on until only one tribe remains. What is the probability that each tribe is the last one standing, given initial population size?
Once again, before coding let's get into the calculation and without the loss of generality, let's consider the probability chance of bear. Let $Pr[B_{i,j,k}]$ be the survival probaility of bears under the assumption that $i$ bears, $j$ ninjas and $k$ bears left. Also let us consider "meetings" as uniformaly consectivly choosen two inhabitants. Let $X_i/Y_i/Z_i$ be $i\in\{1,2\}$-th choice bear/ninja/hunter. The following equality consists of union of pairwise disjunkt occurances and it holds.
$$Pr[(Y_2\cap X_1) \cup (Z_2\cap X_1)\cup (X_2\cap X_1)\cup(Y_2\cap Y_1)\cup (Z_2\cap Y_1)\cup (X_2\cap Y_1)\cup(Z_2\cap Z_1)\\\cup (X_2\cap Z_1)\cup(Y_2\cap Z_1)]=Pr[(X_1\cap(Y_2\cup Z_2\cup X_2))\cup (Y_1\cap(Y_2\cup Z_2\cup X_2))\\\cup (Z_1\cap(Y_2\cup Z_2\cup X_2))]=Pr[(Y_2\cup Z_2\cup X_2)\cap(X_1\cup Y_1\cup Z_1)]\\=Pr[X_1\cup Y_1\cup Z_1]Pr[(Y_2\cup Z_2\cup X_2)|(X_1\cup Y_1\cup Z_1)]=1$$
We can use it to construct an equation for $Pr[B_{i,j,k}]$:
$$Pr[B_{i,j,k}] = Pr[X_1]Pr[Y_2|X_1]Pr[B_{i,j,k}|Y_2\cap X_1]+Pr[X_1]Pr[Z_2|X_1]Pr[B_{i,j,k}|Z_2\cap X_1]\\+Pr[X_1]Pr[X_2|X_1]Pr[B_{i,j,k}|X_2\cap X_1]+Pr[Y_1]Pr[Y_2|Y_1]Pr[B_{i,j,k}|Y_2\cap Y_1]\\+Pr[Y_1]Pr[Z_2|Y_1]Pr[B_{i,j,k}|Z_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$ and $Pr[B_{i,j=0,k>0}]=0$. Using a DP table, the code looks like this and runs in $O(bnh)$: 