Matrix chain multiplication: Greedy approach
Consider the product $ABC$, where


$A$ is $5\times 2$
$B$ is $2\times 3$
$C$ is $3\times 100$


Your algorithm first computes $BC$ (600 products) and then $A(BC)$ (1000 products), for a total of 1600 products.

The optimal solution first computes $AB$ (30 products) and then $(AB)C$ (1500 products), for a total of only 1530 products.



Suppose that $A$ is $a\times b$, that $B$ is $b \times c$, and that $C$ is $c\times d$. There are two possibilities:


Compute $AB$ and then $(AB)C$: cost is $abc + acd = ac(b+d)$.
Compute $BC$ and then $A(BC)$: cost is $bcd + abd = bd(a+c)$.


The first option is preferable if
$$
\frac{b+d}{bd} &lt; \frac{a+c}{ac}
$$
or equivalently
$$
\frac{1}{b} + \frac{1}{d} &lt; \frac{1}{a} + \frac{1}{c}.
$$
For example, above we have $a = 5$, $b = 2$, $c = 3$, $d = 100$. Since
$$
\frac{1}{2} + \frac{1}{100} &lt; \frac{1}{5} + \frac{1}{3},
$$
the order $(AB)C$ is preferable.

Your decision procedure would prefer this order if $c &lt; b$, that is, if
$$
\frac{1}{b} &lt; \frac{1}{c}.
$$
Your condition misses the contribution of $a,d$.