Iterate through all possible values of j in range [ 1 , M ]
for j in range ( 1 , M + 1 , 1 ) : NEW_LINE INDENT dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j + 1 ] NEW_LINE DEDENT