Fill up the dp table
for i in range ( 1 , length + 1 ) : NEW_LINE INDENT dp [ i ] [ arr [ i - 1 ] ] += 1 NEW_LINE for j in range ( 1 , summ + 1 ) : NEW_LINE INDENT if dp [ i - 1 ] [ j ] > 0 : NEW_LINE INDENT dp [ i ] [ j ] += 1 NEW_LINE dp [ i ] [ j + arr [ i - 1 ] ] += 1 NEW_LINE DEDENT DEDENT DEDENT