Master function details

Source: Internet
Author: User
Tags types of functions

I found that I forgot a lot of my mother functions, so I can make up when I have time...

Primary function (Generating function) Details

 

 

 

Last Updated: 2011.4.3

 

1. In view of the picture and layout of the article, the article was re-edited.

2. I have seen many friends on the Internet do not respect others' labor achievements when reprinting, And I will delete the author information in any article. I hope you will keep all the information in the article during reprinting and abide by the copyright regulations.

Some time ago I wrote an article titled detail about backpacks 01, full backpacks, and multiple backpacks. I saw a lot of support people. I am not a great guy, but a person who learns the same way as everyone else, the purpose of writing these articles is to make it easier for everyone to learn and to make it easier for them to review.

 

(The following content is taken to hangdian ACM courseware and Wikipedia)

In mathematicsPrimary functionIs a form of idempotent series. The coefficients of each item can provide information about this sequence. The method for solving the problem using the primary function is calledPrimary Function Method.

 

There are many types of functions, includingCommon functions,Exponential functions,L series,Bell SeriesAndDirichlet Series. You can write a primary function of each of the above types for each sequence. The purpose of constructing a primary function is generally to solve a specific problem. Therefore, the type of primary function depends on the characteristics of the sequence and the type of the problem.

Here are two sentences. If you don't understand them, you can read this article before looking back at it:

 

"The addition law of the combination problem corresponds to the addition of the power of the T of the Power Series"

"The idea of the primary function is very simple-that is, It maps the discrete series and the idempotent series one by one, and converts the interrelationships between the discrete series into the operational relationships between the idempotent series, finally, the construction of the discrete series is determined by the power series form."

Let's take a look at this polynomial multiplication: (you can click to zoom in on all slices)

Figure 1

We can see that:

 

 

1. The coefficients of X are A1, A2 ,... An.
2. The coefficient of X2 is A1, A2 ,... The whole of the two combinations of A2.
.........
The coefficients of N. XN are A1, A2 ,.... The N combination of an (only one ).

The result is as follows:

Figure 2

Definition of the primary function:

For sequences A0, A1, A2 ,... Constructor:

Figure 3

The function g (x) is a sequence of A0, A1, A2 ,... Functions

 

 

Here we will give two examples, which will be analyzed based on the question:

 

First:

Each weight has one weight of one gram, two grams, three grams, and four grams. What kind of weight can be claimed? What are the possible solutions for each weight?

Consider using the primary function to solve this problem:

Let's assume that X represents the weight, X'sIndexIndicates the weight of the weight, as shown in the following code:

One 1 gram weight can be expressed using the 1 + x function,

A two-gram weight can be expressed using the function 1 + X2,

A three-gram weight can be represented by the 1 + X3 function,

One 4-gram weight can be represented by the function 1 + X4,

Do you understand the four statements above?

Let's take 1 + x2 as an example. As we have already said before, X indicates the weight, and X indicates the weight. Here is a weight with a mass of 2.1What does it mean? 1 indicates that the weight of 2 is 0. (Understanding !)

I don't know if you understand it. Let's use the previous sentence here:

"The addition law of the combination problem corresponds to the addition of the power of the T of the power series."

 

 

1 + x2 indicates two conditions: 1 indicates that the weight with the quality of 2 is 0, and X2 indicates that the weight with the quality of 2 is 1.

 

The meanings of various coefficients are described as follows:

The coefficient A before X indicates that the weight of the corresponding quality is a, and 1 indicates that the weight is 0, here, we can't simply think that the corresponding weight should be 0 * X2 if it is 0 (why? Combined with the mathematical formula ).

Tanky Woo's program life: http://www.wutianqi.com/

So, can you understand the meaning of the above sentence?

 

The combination of several weights can be weighed and expressed by the product of the above functions:

(1 + x) (1 + x2) (1 + X3) (1 + X4)

= (1 + x + X2 + X3) (1 + X3 + X4 + X7)

= 1 + x + X2 + 2x3 + 2x4 + 2X5 + 2x6 + 2x7 + X8 + x9 + x10

From the above function:From 1 gram to 10 grams, the coefficient is the number of solutions. (!!! Classic !!!)

For example, there are 2X5 items on the right end, that is, the 5 grams of the solution are 2: 5 = 3 + 2 = 4 + 1; similarly, 6 = 1 + 2 + 3 = 4 + 2; 10 = 1 + 2 + 3 + 4.

Therefore, there are 2 solutions for 6 grams and 1 solutions for 10 grams.

Next, the second case is as follows:

 

Calculate the number of stamps with a value of 1, 2, and 3:

What is the difference between this situation and the first one? The first one is one, and the second one is infinite.

Figure 4

Take the expanded X4 as an example. The coefficient is 4, that is, the number of splits 4 into the sum of 1, 2, and 3 is 4;

That is, 4 = 1 + 1 + 1 + 1 = 1 + 1 + 2 = 1 + 3 = 2 + 2

Here we will introduce two concepts: integer splitting and Splitting:

The so-calledInteger splittingThat is, the integer is divided into the sum of several integers (equivalent to placing N non-differentiated balls in N unsigned boxes. The box can be empty or put more than one ball ).

An integer is split into the sum of several integers in different ways. The total number of different sharding methods is calledSplit score.

In the second case above, the number of each type is infinite.Template:

 

Figure 5

# Include <iostream> <br/> using namespace STD; <br/> // Author: tanky Woo <br/> // www.wutianqi.com <br/> const int _ max = 10001; <br/> // C1 indicates the number of mass weights that can be combined. <br/> // C2 indicates the intermediate quantity, if the storage fails once, <br/> int c1 [_ max], C2 [_ max]; <br/> int main () <br/> {// int N, i, J, K; <br/> int nnum; // <br/> int I, j, k; </P> <p> while (CIN> nnum) <br/> {<br/> for (I = 0; I <= nnum; ++ I) // ---- ① <br/>{< br/> c1 [I] = 1; <br/> c2 [I] = 0; <br/>}< br/> for (I = 2; I <= nnum; ++ I) // ----- ② <br/>{</P> <p> for (j = 0; j <= nnum; ++ J) // ----- ③ <br/> for (k = 0; k + j <= nnum; k + = I) // ---- ④ <br/>{< br/> c2 [J + k] + = c1 [J]; <br/>}< br/> for (j = 0; j <= nnum; ++ J) // ---- ⑤ <br/>{< br/> c1 [J] = c2 [J]; <br/> c2 [J] = 0; <br/>}< br/> cout <c1 [nnum] <Endl; <br/>}< br/> return 0; <br/>}

Let's explain the areas of the above sign :(***********!!! Key points !!!***********)

① Initialize C1 first, and initialize the first expression (1 + x + X2 +... XN) to initialize all weights with quality from 0 to n to 1.

②. I traverses from 2 to N. Here I refers to the I expression. In the second form of the parent function, each bracket is an expression.

③ J traverses from 0 to N. Here J is the J variable in the (I previously wrote the formula for table multiplication, (Here, let's take a look at the comment my friend pointed out to me. You can check the comment at the message center ). For example, (1 + x) (1 + x ^ 2) (1 + x ^ 3), J indicates the coefficients of 1 and X, and I = 2 changes
(1 + x ^ 2 + x ^ 3) (1 + x ^ 3). In this case, J indicates the coefficients of the four variables in the first parentheses after the merge ..

 

4. k indicates the J-th index, So k increases I each time (because the increment of the I-th Expression is I ).

 

⑤ Assign the value of C2 to C1, and initialize C2 to 0, because C2 starts from an expression each time.

 

Let's catch up with some questions:

 

(The corresponding question Parsing is analyzed in the corresponding code)

1. Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1028

Code: http://www.wutianqi.com /? P = 587

Is this simple? I understood the template above. This is a small case!

Let's look at this question:

2. Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1398

Code: http://www.wutianqi.com /? P = 590

To tell the difference from the previous question, you only need to change two places. When I traverses the expression (refer to my document-), I <= nnum is changed to I * I <= nnum, then, K + = I is changed to K + = I * I when K traverses the index. OK. Let's say it's still a set of templates ~~~

3. Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1085

Code: http://www.wutianqi.com /? P = 592

This question has finally changed a bit, but it cannot be left alone.

After a good analysis, you will understand the code.

4. Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1171

Code: http://www.wutianqi.com /? P = 594

There are also some questions that you have time to do on your own:

Hdoj: 1709,1028, 1709, 1085, 1171, 1398, 2069, 2152

(For original articles, you are welcome to repost them, but please do not delete any links in the articles. Please consciously respect the copyright of the articles. This is a violation of the law. Thank you for your cooperation. Tanky Woo original, www.wutianqi.com)

Appendix:

 

1. In Wikipedia, we talked about the numbers of common mother letters, typical mother letters, numbers of L-grams, typical numbers, and Dirichlet numbers:

Http://zh.wikipedia.org/zh-tw/%E6%AF%8D%E5%87%BD%E6%95%B0

2. matrix67 Daniel: What is a function generation:

Http://www.matrix67.com/blog/archives/120

3. You can take a look at the main function of the ACM Courseware of hangdian. The pictures and some content here are all taken there.

 

**************************************** **************************************** *************

Reprinted from tanky Woo

Http://www.wutianqi.com /? P = 596

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.