Optimized matrix sequence multiplication, optimized dynamic programming algorithms for memory usage