The correct way
cols =. 3
rows = 2
memo = [[1] * m for i in range(n) ]
Below this approach is wrong
memo = [[1] * m ] * n
This causes the memo [0] == memo [1], wherein changing the value of a sub-array, the array will change along with the other sub-