I was working on Wall Street Monopoly at UCF Local Programming Contest in 2012. My professor explained this is Matrix Chain Multiplication, but it took me a while to get how to apply Matrix Chain Multiplication to this problem. So here is a little note for myself.
Wiki’s pseudocode doesn’t save the generated matrix dimension from multiplication, and I didn’t get how p[] computes the cost of multiplication, so I created 3D array to save the result of multiplication of matrix.
Here is my basic code for Matrix Chain Multiplication
Then, to calculate the minimum multiplication cost, I do it recursively and save the result of calculation in 2D array memo
So here is my core code for Matrix Chain Multiplication. I changed this code to this. The change I made is how I set up matrixDimension and the value I add in solve function.
Here is all my change I made! Summarixing this as a document helps me to grasp what I did. Hope this helps future programmers!