Didn't understand the concept

Why is the dp array only dependent on i and j. Shouldn’t it be a function of y as well?

no because y is also depend on i and j
so no need of y
we can get y using i and j