L is substring length . Build the solution in bottom - up manner by considering all substrings of length starting from 2 to n . The loop structure is the same as Matrix Chain Multiplication problem ( See https : www . geeksforgeeks . org / matrix - chain - multiplication - dp - 8 / )
for L in range ( 2 , n + 1 ) : NEW_LINE