And two-dimensional prefix and prefix &

We know the prefix array and S [i] = S [i-1] + a [i]

So, how to find it and the two-dimensional prefix?

And two-dimensional prefix:

Prefix and is yellow, red, gray and green right point and green point

How to calculate?

s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];

Prefix portion and green = (red + gray) + (gray yellow +) - Gray Green +

 

With prefix and, how to calculate the point and the right to a certain part of it?

Similarly, the sum of the green parts now = S (4,4) -S (4,2) -S (2,4) + S (2,2)

We set a side portion of the green rx * ry, a sum, the green part of the lower right corner coordinates i, j

a[i][j]=s[i][j]-s[i-rx-1][j]-s[i][j-1-ry]+s[i-1-rx][j-1-ry];

 

Guess you like

Origin www.cnblogs.com/lzy-blog/p/11105891.html