Python3 program for the above approach
N = 1005 ; NEW_LINE K = 20 ; NEW_LINE n = 0 NEW_LINE k = 0 NEW_LINE dp = [ [ [ - 1 for k in range ( K + 1 ) ] for j in range ( N + 1 ) ] for i in range ( N + 1 ) ] NEW_LINE