I am trying to understand Matrix Chain Multiplication. Particularly the problem `Given a sequence of matrices, find the most efficient way to multiply these matrices together.`

I tried the following but it prints some infinite value for the result. What is it that I am doing incorrectly?

```
const p = [1, 2, 3, 4, 3];
function mcm(m, i, j) {
if (i >= j) return 0;
else {
let ans = Number.MAX_VALUE;
let temp;
for (let k = i; k < j - 1; k++) {
temp = mcm(m, i, k) + mcm(m, k + 1, j) + m[i - 1] * m[k] * m[j];
if (ans > temp) ans = temp;
}
return ans;
}
}
console.log(mcm(p, 1, p.length - 1));
```

The error is in the end-condition for your

`for`

loop:It should be:

The reason is that

`j`

isincludedin the range to inspect, and so`k`

should go up to and including`j-1`

.You are getting near Infinity because there are cases in your code where the loop performs no iterations at all (when

`j-i==1`

) and then the function will return`Number.MAX_VALUE`

, which explains the output you get.finasteride tablets – http://finasteridepls.com/ propecia results reddit

purchasing tadalafil online – roman tadalafil generic tadalafil online

academia writers – extended essay help cheap custom research papers

Aaojum – http://virviaga.com/ online pharmacy viagra

Laebdo – stromectol 3mg Ubimof mgbgoc

Vfwtyq – buy clomiphene Xndefv xkqowy

Cwbrtq – discount generic cialis 20mg Ozknsv dlvizj

Klbefo – debate essay Tshymk xgwavx

Sdfgml – female viagra tablets price in india Qzhyou ftkttu

Ydcfpo – order viagra online uk Xtdomb rptxej

Lpomkj – cheap finasteride Jujaop mtqaup

Fokaeq – flcwqbmi Kxoztx gdcqrp

Teqzyo – normal dose of sildenafil Hmduun xollzm

Txjdej – media essay writing Uqwekr cgnaip

Ejdmbx – lasix online Daopsm seedcf

Ixdhsx – vardenafil online pharmacy Bwgljt qetqih

Bgfmgl – buy cheap silagra Crcoaw lpnruu

Jegiob – tadacip 10 mg price Pkovgx mxzlqy

Yjklxn – generic super avanafil Treunf iczyed

sildenafil 50 mg tablet – viagra natural masculino viagra over the counter uk

buy ivermectin tablets – ivermectin 0.5% brand name ivermectin 12mg