Use an allocated matrix for the dynamic programming algorithm.
Fix error in allocation
Remove malloc stuff again (bad performance).