Sum of submatrix approach 3

sum+=arr(i,j) * ( (i+1,j+1) * (n-i,m-j))

in this line why are we adding 1 to i and j and subtracting i and j from n and m respectively

hi
in this approach our aim is to calculate contribution of each cell

as explained in video how to calculate this

we have to select 2 points top left and bottom right
for top left selected rectangle is from 0,0 to i,j
and no of element in it is length * breadth
length=i+1;
breadth=j+1;
so it is (i+1)(j+1)
similarly for bottom right point selection
length=(n-1 -i +1)=n-i;
breadth=(n-1 -j +1)=n-j
so it is (n-i)(n-j)

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

for more clearity watch video again