Not able to think of the approach

i am unable to get the appraoch of this problem … how can we apply dp here ?? what should be the thought process in making the solution?? the hint video is very confusing … and didn’t find it helpful plz help on this

Hey @Shobhit_kumar read this carefully, and try to understand this,
Let’s solve the problem for rectangle W×H (W≥H). Of course, we can cover all rectangle with itself for cost W. To get something smaller than W we have to leave at least one column uncovered — otherwise we pay at least sum of w over all rectangles which is at least W. This gives us an idea to use DP on rectangles to solve the problem: dp[x1][x2][y1][y2] is minimal cost to cover the rectangle [x1;x2)×[y1;y2). It is initialized by max(x2−x1,y2−y1), and we have to try not to cover every column/row. Of course, we have to check if it is all white from the beginning; to do that we will precalculate 2D prefix sums. Total complexity is O(5*n).
W and H are width and height of rectangle drawing canvas
For our question W = H = N because its a square
If you use eraser at each valid position complexity will be 0(n^4)

Your solution can have at max 0(n^3)
So pre-calculate number of black cells in each k size segment in rows and cols
When you place an erase somewhere, row will become white if black cells in row == black cells in k size segment from that position
Similarly you can solve for columns

So n^2 cells and n time at each cells gives 0(n^3)

Moreover if it’s still not understandable, refer this.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.