UOJ424 Count generating functions, polynomial inverse matrix fast power

Portal


Two identical sequences if and only if they have the same Cartesian tree, then becomes Cartesian tree count.

Then notice how every single point of weight would certainly be a large weight that left his son, so the Cartesian tree is not able to exist a number of times from the root to a node of the path to the left to go to meet the \ (> m-1 \) . This condition is difficult to prove and only \ (n \ geq m \) conditions are satisfied, there is a certain allocation weights that \ (1 \) to \ (m \) are assigned to.

May assume \ (F_i (x) \) represents the number of left to go is less than \ (I \) Number Cartesian tree generating function, namely \ (f_ {i, j} \) represents \ (J \) points the number left to go is less than \ (i \) the number of Cartesian tree.

Then there is \ (F_0 (X) =. 1, F_i (X) = F_ {I}. 1-X \ F_i Times (X) \ X Times. 1 + \) , which represents the number of times to go to the left to choose a root less than \ (i-1 \) Cartesian tree as its left son, left to go to select a number less than \ (i \) of Cartesian tree as his right son. You can be \ (F_i (X) = \ {FRAC. 1. 1} {-}. 1-xF_ {I (X)} \) .

Set \ (I-F_ {}. 1 (X) = \ FRAC {A} {B} \) , then \ (F_i (X) = \ FRAC {B} {} xA-B \) . Transfer can be represented by a matrix multiplication, i.e., \ (\ left (\ begin { array} {cccc} A & B \ end {array} \ right) \ times \ left (\ begin {array} {cccc} 0 & -x \ \. 1. 1 & \ Array End {} \ right) = \ left (\ Array the begin {} {} CCCC B & B - xA \ Array End {} \ right) \) , fast power considering matrix optimization process.

So we need to address the question of how fast polynomial multiplication and addition, it is easy to think first of all polynomials DFT calculated value represents its point, so just multiply and additions to the polynomial point in the process of rapid exponents of the matrix. Finally IDFT to obtain an inverse polynomial coefficients after seeking to find the answer.

Remember Laid sentence \ (n <m \) when the answer to \ (0 \) .

Code

Guess you like

Origin www.cnblogs.com/Itst/p/11314428.html