Beginner generation function (a) - generating function Normal

Foreword

Generating function is a very useful thing.

However, due to my bad math foundation, and therefore I have not learn. I do not think they understand polynomial multiplication, even learn to not take too, will not continue to adhere to the study.

However, this time I finally found a relatively conscience blog, and finally as a way to generate a function of the initial entry.

Start with a simple knapsack problem

Consider this question:

There \ (4 \) kinds of goods, the number of each item are as follows: \ (\ {1,2,3,1 \} \) . Definition of two different programs selected items of different numbers if and only if the presence of at least one item selection, request select \ (5 \) number of program items.

If you would dynamic programming, then with a backpack can easily solve this problem, there is not much to say.

Now our focus is on how to use the generating function of thinking to solve this problem.

The basic function of generating meaning

We consider each item expressed as a polynomial (actually generating function ): \ (\ I = {0} sum_ ∞a_ix ^ I ^ \) .

Wherein \ (I \) order term \ (x ^ i \) a coefficient \ (a_i \) , represents select \ (I \) number of a program items. And here \ (the X-\) , and does not make any sense.

For the first \ (1 \) kinds of goods, only two options: choose or not to choose \ (1 \) a program number is \ (1 \) . We can use a polynomial it is represented as \ (the X-^ 0 ^ + the X-1 \) (ie \ (the X-1 + \) ).

For the first \ (2 \) kinds of goods, there are three options: do not choose or choose \ (1 \) or choose \ (2 \) months. We can also use a polynomial it is represented as \ (the X-+ 1 + the X-^ 2 \) .

For the first \ (3 \) kinds of goods, there are four options: do not choose or choose \ (1 \) or choose \ (2 \) or choose \ (3 \) months. We can still use a polynomial it is represented as \ (the X-+ 1 + 2 + the X-the X-^ ^ 3 \) .

For the first \ (4 \) kinds of goods, only two options: choose or not to choose \ (1 \) one. We can still use a polynomial it is represented as \ (the X-1 + \) .

So, we managed to put \ (4 \) types of items into a \ (4 \) polynomials.

Next, let's explore what the nature of polynomial multiplication Yes.

For example, we want to \ (\ sum_ {i = 0 } ^ ∞a_ix ^ i \) and \ (\ sum_ {i = 0 } ^ ∞b_ix ^ i \) multiplied together, then we can separately in two pieces polynomials For each item.

In the first enumeration to assume a polynomial in \ (a_ix ^ i \) , in the second formulas to enumerate \ (b_jx ^ J \) , then we'll answer in polynomial representing a plus \ (I + J a_ib_jx ^ {} \) .

Consider the practical significance of this operation, in fact: if our elected in the first article \ (i \) a, the second item selected \ (j \) a total on elected \ (i + j \) th, thus the selected \ (i + j \) number of program items plus the selected items in the first \ (I \) a number of programs and selecting a second article in \ (j \) a number of programs the product.

This seems to give us some insights. That is, after multiplying two polynomials, which for the first (i \) \ meaningful entry times coefficients, still in line with our original intention.

If we take the example above \ (4 \) polynomials multiplied together, you can get:

\[(1+x)(1+x+x^2)(1+x+x^2+x^3)(1+x)=1+4x+8x^2+11x^3+11x^4+8x^5+4x^6+x^7\]

The polynomial coefficients \ (\ {1,4,8,11,11,8,4,1 \} \) , also representing the selected \ (0 \ sim7 \) number of program items.

So we answered that question above, namely elect \ (5 \) number of items for the program \ (8 \) .

At this point, the significance of the basic generation function, it is essential to explain finished.

However, the basic generating function exactly what use is it? As can be seen from the above example, it does not seem to play any time complexity for optimization.

This requires its further transformed.

The basic function of generating further conversion

Generating a basic conversion function is further directed to a derivation formula, i.e. (x∈ (-1,1) \) \ time, \ (\ I = {0} sum_ ∞x ^ I ^ = \. 1-X} {frac1 \) , certify as follows:

\(S=\sum_{i=0}^∞x^i\),则\(xS=\sum_{i=1}^{∞+1}x^i\)

Because of \ (∞ + 1 \) still can be regarded as infinite, so we can think \ (xS = \ sum_ = {I}. 1 ∞x ^ I ^ \) .

\(xS-S=\sum_{i=1}^∞x^i-\sum_{i=0}^∞x^i=-1\),即\((x-1)S=-1\)

So \ (S = \ {-1} {FRAC. 1-X} = \ frac1. 1-X} {\) .

In this way, we'll give a polynomial and turned it into a simple equation.

Note that here, although more out of \ (x ∈ (-1,1) \) , can be as I said before, \ (the X-\) does not make any sense, so much that this restriction does not have any relationship.

In fact, with this transformation, we can make the generating function play a greater role.

Simple application of the basic functions generated

According to some simple transformation, we can get some transformed the relationship between the common restriction and generation functions.

  • Can not exceed the requirements of the selected \ (K \) : \ (\ sum_ {I} = 0 ^ ^ I = KX \ FRAC. 1-X ^ {K +. 1 {{}}}. 1-X \) .

  • The number must be asked to choose \ (K \) multiple: \ (\ sum_ {I} = 0 {^ IK ^ ∞x} = \ sum_ {0} ^ = I ∞ (X ^ K) = ^ I \ . 1-X ^ {frac1} K \) .

At the same time, we must know a significant and practical formula: \ (\ frac1 {(. 1-X)} = ^ K \ sum_ I = {0} + I {^ ∞C_-K-K. 1. 1} ^ { I X ^} \) .

Briefly, the function is to generate the \ (\ frac1 {(1- x) ^ k} \) a \ (I \) coefficient order term is \ (C_ {i + k- 1} ^ {k-1} \ ) , prove the following:

\(\frac1{(1-x)^k}=(\frac1{1-x})^k=(\sum_{i=0}^∞x^i)^k\)

The final set \ (x ^ i \) generated way \ (X = I ^ \ prod_. 1} = {P ^ {^ KX a_p} \) , then \ (x ^ i \) is in fact equivalent to the coefficient obtaining the number of length \ (P \) array \ (a \) is satisfied:

  • \ (\ sum_ {p = 1} 'ka_p = i \) .
  • For any \ (P (. 1 \ Le P \ Le K) \) , satisfies \ (a_p \ GE 0 \) .

This is actually seeking to \ (i \) th items into \ (k \) number scheme may be an empty set, we can use the law to obtain a separator.

This process is equivalent to considering the \ (I \) selecting an article \ (k-1 \) slits (reusable), insert \ (k-1 \) plate.

The total \ (i + 1 \) slits for inserting, if the slot as per a new article, and then added \ (k-2 \) new article in which the first \ (T \) th represents \ (t + 1 \) plate whether the first \ (T \) on the plates together.

Therefore, it is equivalent to \ ((i + 1) + (k-2) = i + k-1 \) selecting an article \ (k-1 \) th items, the program number is \ (C_ {i + ^ {}. 1-K-K. 1} \) .

example

[2000] Luo Gu save the world

Guess you like

Origin www.cnblogs.com/chenxiaoran666/p/GeneralGeneratingFunction.html