I recently started learning dynamic programming, while solving some classical problems I encountered 2D range sum, and this which were solved using dp with inclusion and exclusion. Can anyone explain how can I tackle this types of problems? Any help will be appreciated.
To solve this problem, i search all posible squares and add to the solution. All this can be doing in O(n^3*logn) (if you search all intervals and then doing a binary search). You can see my code. By inclusion and exclusion, I dont know how to do it.