501-511NOIP training camp serpentine matrix 17--

Portal: QAQQAQ

 

Meaning of the questions: small X in the words of a child, will do a standard serpentine matrix, and found a lot of fun. X now want to be small revision, changes of the type of an infinite number of serpentine array:
1.jpg
Order S (x) as represented in the upper left corner 1, x is within the lower right corner of the rectangle and the number of all. E.g. S (12) has a dark background and is the number of.
Given n, for the "top left corner 1, n-rectangular lower right corner" in every number i is calculated for all S (i) sum.

 

Ideas: Fairy math. . .

Violence look: by doing so we can draw a simple projection and YY formula: $ ans = \ sum_ {i = 1} ^ {n} \ sum_ {j = 1} ^ {m} a_ {i, j} * \ left (n-i + 1 \ right) * \ left (m-j + 1 \ right) $

Then we can solve the problem within the complexity of $ O (n) $ of

 

Now start optimizing links: We can put a given rectangle split into several strands, each strand is to make a continuous series ( inexplicable think of tree chain split ... )

Specific methods of resolution are as follows: If a rectangle, the first redundant row or column split out, put it into a square. Then, for each lap, let's split $ rnd $ months on end, and then sideways split $ rnd-1 $ a, so the split is complete.

Now our task is to find a sequence of continuous and. Statistical sum of each of $ a_ {i, j} * \ left (n-i + 1 \ right) * \ left (m-j + 1 \ right) $, and this sequence must be in the same row or column, so we can $ \ left (n-i + 1 \ right) $ or $ \ left (m-j + 1 \ right) $ in an extracted, so that the rest of the sum is multiplied by two . And we find these two arithmetic series in two separate tolerance for the $ 1 $ or $ -1 $ in.

 

Now part of mathematics - violent push formula

Order $ f (s1, s2, d1, d2, n) $ item led to $ s1 $, $ tolerance arithmetic sequence D1 is the first item and $ $ s2 $, $ tolerance arithmetic each column D2 $ multiplying each item, the product item before $ and $ n-

即:$f(s1,s2,d1,d2,n)$=$\sum_{i=1}^{n}\left [ s1+\left ( i-1 \right )*d1 \right ]*\left [ s2+\left ( i-1 \right )*d2 \right ]$

          =$\sum_{i=1}^{n}(s1*s2)+\sum_{i=1}^{n}(s1*d2*(i-1))+\sum_{i=1}^{n}( d1*s2*(i-1))+\sum_{i=1}^{n}( d1*d2*(i-1)^{2} )$

          =

Guess you like

Origin www.cnblogs.com/Forever-666/p/11286038.html