Getting started with the parent function + templates

Source: Internet
Author: User
Tags power of power

In mathematics, the parent function of a sequence (generating function, also known as a generative function) is a form power series whose coefficients can provide information about the sequence. The method of solving a problem by using a parent function is called a parent function method.

The female function can be divided into many kinds, including common parent function, exponential parent function, L series, Bell series and Dirichlet series. For each sequence, you can write a parent function for each of these types. The purpose of constructing a parent function is generally to solve a particular problem, so the choice of which parent function depends on the nature of the sequence itself and the type of problem.

Here first give two words, do not understand can wait to read this article and then back to see:

1. "Match the rule of addition of combinatorial problems with the power of power series"

2. "The idea of a female function is very simple--that is, the discrete series and the power series one by one corresponding to the discrete sequence of the mutual relationship between the power series to the operational relationship, and finally from the form of power series to determine the structure of discrete series." “

Let's look at this polynomial multiplication first:

Parent function diagram (1)

From this we can see:

The coefficient of 1.x is a1,a2,... an individual combination of the whole.

2. The coefficient of x^2 is the A1,A2,... the total of two combinations of A2.

.........

N. The coefficient of x^n is the total of n combinations of A1,a2,.... an (only 1).

Further get:

Parent function Diagram (2)

Definition of the parent function

For sequence a0,a1,a2, ... Construct a function:

Parent function Diagram (3)

Called function g (x) is a sequence of a0,a1,a2, ... 's parent function.

Here first give 2 examples, and so on will be combined with the topic analysis:

The first type:

1 grams, 2 grams, 3 grams, 4 grams of weight each one, can weigh what kinds of weight? How many possible options are available for each weight?

Consider using a parent function to solve this problem:

We assume that x represents weights, and the exponent of x represents the weight of weights, so:

A 1 gram weight can be represented by the function 1+1*x^1,

A 2 gram weight can be represented by the function 1+1*x^2,

A 3 gram weight can be represented by the function 1+1*x^3,

A 4 gram weight can be represented by the function 1+1*x^4,

These four formulas above, you know?

For 1+x^2, we have said earlier that X represents weights, and X's exponent represents weight! At the initial state, this is a weight of 2.

So what does the previous 1 mean? According to the above understanding, 1 should actually be written as: 1*x^0, that is, 1 for weight of 2 weights of 0.

So here 1+1*x^2 = 1*x^0 + 1*x^2, that means 2 grams of weights have two states, not take or take, not take is 1*x^0, take is 1*x^2

Do not know that everyone understands not, we here combine the preceding sentence:

"The addition rule of combinatorial problems corresponds to the power of power series".

Then we discuss the above 1+x^2, what is the meaning of the coefficients in front of x?

The coefficients here represent the number of States (scheme number)

1+x^2, that is, 1*x^0 + 1*x^2, which is said above not take 2 grams of weight, at this time there are 1 states, or 2 grams of weight, at this time there are 1 states. Analysis )

So, what is the meaning of the sentence that we have said before can you understand?

The combination of several weights can be weighed, and can be represented by the product of several of these functions:

(1+x) (1+x^2) (1+x^3) (1+x^4)

= (1+x+x^2+x^4) (1+x^3+^4+x^7)

=1 + x + x^2 + 2*x^3 + 2*x^4 + 2*x^5 + 2*x^6 + 2*x^7 + x^8 + x^9 + x^10

From the above function know: can be weighed from 1 grams to 10 grams, the coefficient is the number of schemes. (!!! Classic!!! )

For example, there are 2^x^5 items at the right end, that is, there are 2 ways to weigh 5 grams: 5=3+2=4+1; 6=1+2+3=4+2;10=1+2+3+4.

Therefore, the number of 6 grams of the program has 2, said 10 grams of the program number of 1.

Next up, here's the second case:

The second type:

1, 2, and 3 stamps are used to post different numbers of programs:

What is the difference between this situation and the first comparison? The first of each is one, and each of these is infinite.

Parent function Diagram (4)

Take the expanded x^4 as an example, its coefficient is 4, that is, 4 split into 1, 2, 3 of the sum of the number of split scheme is 4;

namely: 4=1+1+1+1=1+1+2=1+3=2+2

Here again, two concepts, "integer split" and "split fraction" are drawn:

The so-called integer splitting is the sum of the integers divided into integers (equivalent to the N-no-difference ball in the N unmarked box, the box is allowed to be empty, and more than one ball can be placed).

Integers are divided into several integers, with different methods, and the total number of split methods is called split fractions.

Now in the second case above, for example, the number of each species is infinite, the template is given:

1#include <iostream>2 using namespacestd;3 //Author:tanky Woo4 //www.wutianqi.com5 Const int_max =10001; 6 //C1 is the number of weights that can be combined to preserve each weight7 //C2 is the middle volume, saving every time the situation8 intC1[_max], C2[_max]; 9 intMain ()Ten{//int n,i,j,k; One     intNnum;//  A     intI, J, K; -  -      while(Cin >>nnum) the     { -          for(i=0; i<=nnum; ++i)//----① -         { -C1[i] =1; +C2[i] =0; -         } +          for(i=2; i<=nnum; ++i)//-----② A         { at  -              for(j=0; j<=nnum; ++J)//-----③ -                  for(k=0; k+j<=nnum; K+=i)//----④ -                 { -C2[j+k] + =C1[j]; -                 } in                  for(j=0; j<=nnum; ++J)//----⑤ -                 { toC1[J] =C2[j]; +C2[J] =0; -                 } the         } *cout << C1[nnum] <<Endl; $     }Panax Notoginseng     return 0; -}

Let's explain the various places above the logo: (***********!!! Focus!!! ***********)

①, first initializes the C1 by the first expression (1+x+x^2+. X^n) is initialized to initialize all weights from 0 to N of the mass to 1.

②, I from 2 to n traversal, here I refers to the first expression, the second type of parent function, given above, each parenthesis is an expression.

③, J traversal from 0 to N, here J is (the expression of the previous expression multiplicative) j variables, (here to thank the Seagg friend to me pointed out the error, you can see the discussion in the message). For example (1+x) (1+x^2) (1+x^3), J first indicates the coefficients of 1 and X, and i=2 after execution becomes

(1+x+x^2+x^3) (1+x^3), when J should indicate the coefficients of the four variables of the first parenthesis after merging.

④, K is the first J exponent, so k increments I each time (because the increment of the I-expression is i).

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

Let's hurry up and strike a few questions:

(the corresponding problem analysis is analyzed in the corresponding code)

1. Title: http://acm.hdu.edu.cn/showproblem.php?pid=1028

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

Let's look at the simple question. The above template is understood, this problem is small case!

Look at this question:

2. Title: http://acm.hdu.edu.cn/showproblem.php?pid=1398

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

To say the difference from the previous question, we only need to change 2 places. When I traverse the expression (can refer to my data-"mother function in detail"), the i<=nnum changed to I*i<=nnum, followed by the K-Traversal index k+=i into a k+=i*i; Ok, it's still a set of templates ~ ~ ~

3. Title: http://acm.hdu.edu.cn/showproblem.php?pid=1085

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

The problem finally changed a little, but the change is not one of them.

The analysis, the combination of code will understand.

4. Title: http://acm.hdu.edu.cn/showproblem.php?pid=1171

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

There are some questions that you have time to do yourself:

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

(original article, welcome to reprint, but please do not delete the link in the article, please consciously respect the copyright of the article, partiality, thank you for your cooperation. Tanky Woo Original, www.WuTianQi.com)

Report:

1. In Wikipedia, you'll talk about common parent functions, number of letters, L class, the number of grades, and Dirichlet:

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

2. Matrix67 Daniel There is an article: what is a build function:

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

3. You can take a look at Hang Electric's ACM courseware, the parent function of the article, my picture here and some of the content is led to that.

If you have a problem or the contents of the material is wrong, you can leave a message, blog: http://www.wutianqi.com/

Tanky Woo original article, reproduced please indicate the source: http://www.wutianqi.com/?p=596.

For any reprint of this blog post and do not retain the original link or arbitrary deletion of the link in the text of the behavior, I will certainly deal with the end!

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

Here are some questions he gave the code for the template (or the answer to the 1028 question) instead of the second answer. Just say the author of this article is very powerful.

Getting started with the parent function + templates (GO)

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.