# ACM NUMBER Theory Tour---mother function (also called generative function) (Pain and Happiness (╭￣3￣) ╭)

Source: Internet
Author: User

(The front row sells snack melon seeds)

Foreword: (???? No, it will be a disadvantage.)

The next algorithm is more difficult, the general people do not understand, because you can not use ordinary thought to understand

It's like a high number (it's a lot of Tears (>﹏<). )）

You have to use conventional methods to think it must be tiring (￣▽￣) ~*

Sometimes it's more efficient to read a few times over and over.

Just like the matrix, the person who invented the matrix is a genius, we can only use the matrix at the same time always sigh: "Wow!" It's amazing! This is also possible! ”

Instead of first studying why he would have so many magical properties

Because, after all, from the inventor's point of view, he was thinking so much to create a magical matrix.

And if each of the properties of the matrix you are a little bit study the past, one day, you can also like him to fully understand the matrix, but the time is too long

So, sometimes, you just have to learn to use the nature of the matrix, and then one day, maybe, you know the principle of it (ㄒoㄒ)/

In short, the next thing I say, I can understand it, I don't know it, I remember it first.

generating function, which is a parent function, is an important theory and tool in combinatorial mathematics, especially in counting.

But the parent function in ACM is like math, and it's all about the basics of the female function.

(Just like the formula of the equation, the decomposition of the type, it is easy to write, you use the computer to write up the trouble, so learn computer do not old with mathematicians nonsense (￣3￣))

What is a female function

is to combine a known sequence with a polynomial of x, and the newly created polynomial is called the parent function of the original sequence.

As for how to merge, look at this example

The parent function of the sequence {0,1,2,3,4,5...N} is

F (x) =0+x+2x^2+3x^3+4x^4+...+nx^n (this x has no meaning, it should be said, you don't need to think of it as a function, you just have to know that the parent function says so.)

Sequence {1,1,1,1,1 ...} The parent function is

F (x) =1+x+x^2+x^3+x^4 ....

The sequence of two-item expansion such as this {1,4,6,4,1,0,0,0,0,0 ...} is the C (4,0) to C (+) coefficient, then its parent function is

F (x) =1+4x+6x^2+4x^3+1x^4

The mother function is long like this, for normal people, this kind of thing is meaningless (° °| | |)

That something meaningful (the following are classic questions, I copied from the Hangzhou Electric ACM Courseware)

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?

If the power of x represents a few grams of weight

So

1 grams of weight expressed as 1+x^1

2 grams of weight expressed as 1+x^2

3 grams of weight expressed as 1+x^3

4 grams of weight expressed as 1+x^4

Each weight can be selected or not taken

So here's 1 can think of 1*x^0, said not to take this weight

Then multiply these.

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

=1+ (x^1) + (x^2) +2 (x^3) +2 (x^4) +2 (x^5) +2 (x^6) +2 (x^7) + (x^8) + (x^9) + (X^10)

According to the index, we can weigh so much 0~10, where the coefficient of 3~7 is 2, indicating that there are 2 ways to weigh

So let's look at it again.

0: (no weight to put) ......... ........ (1 types)

1:1 ..... ..... ........................... (1 types)

2:2 ..... ..... ........................... (1 types)

3:3 or 1+2 ..... (2) .......----------------

4:4 or 1+3 ..... (2) .......----------------

5:1+4 or 2+3 ..... (2 kinds of) ........ (There are no more than a few).

6:2+4 or 1+2+3 ..... (2 kinds of ...)...----------

7:3+4 or 1+2+4 ..... (2 kinds of ...)...----------

8:1+3+4 .... (1 kinds of) ......----------------...

9:2+3+4 .... (1 kinds of) ......----------------...

10:1+2+3+4 .... (1 kinds of) ......... (There are no more than a few of them).

Exactly (??? *)

So the parent function is so used in ACM, it doesn't matter with the function, it is related to the writing ...

One more question.

1, 2, and 3 stamps are used to post different numbers of programs: (the number of each stamp is unlimited)

So

1 points: (1+x^1+x^2+x^3+x^4+ ...)

2 points: (1+x^2+x^4+x^6+x^8+ ...)

3 points: (1+x^3+x^6+x^9+x^12+ ...)

Then the 3 of them multiply (let the computer ride it)

For this infinity, the topic will certainly give you the range of values he inquired about, and the maximum range would be calculated.

Attached code:

`1#include <cstdio>2typedefLong LongLL;3 Const intN = -+5;//if the title only asks until 1004 Const intMAX =3;//There are only 3 types of stamps on the subject .5LL C1[n], c2[n];//C2 is a polynomial of temporary merging, and C1 is the final merged polynomial6 intN;7 voidinit () {8      for(inti =0; i < N; i + +) c1[i] =1;//1-cent stamp9      for(inti =2; I <= MAX; i + +) {//Merge 2 points to maxn stamps into a polynomialTen          for(intj =0; J < N; J + = i) {//I-Points stamp, step is I One              for(intK =0; J + K < N; K + +) {//from x^0 to X^n to traverse through AC2[j + K] + = c1[k];//because J has all the term coefficients of 1, so c1[k] can be regarded as c1[k]*1; -             } -         }  the          for(intj =0; J < N; J + +) {//Copy the C2 data to C1 and empty the C2. -C1[J] =C2[j]; -C2[J] =0; -         } +     } - }  + intMain () { A init (); at      while(SCANF ("%d", &n)! =EOF) { -printf"%i64d\n", C1[n]); -     } -}`

We're going to use this template for real.

HDU 1028

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

The question asks a number n How many numbers can be split and

Like n=4.

4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;

There are 5 kinds, then the answer is 5.

AC Code:

`1#include <cstdio>2typedefLong LongLL;3 Const intN = -+5; 4 Const intMAX = -+5; 5 LL C1[n], c2[n];6 intN;7 voidinit () {8      for(inti =0; i < N; i + +) c1[i] =1;9      for(inti =2; I <= MAX; i + +){ Ten          for(intj =0; J < N; J + =i) { One              for(intK =0; J + K < N; K + +){  AC2[j + K] + =C1[k]; -             } -         }  the          for(intj =0; J < N; J + +){  -C1[J] =C2[j]; -C2[J] =0; -         } +     } - }  + intMain () { A init (); at      while(SCANF ("%d", &n)! =EOF) { -printf"%i64d\n", C1[n]); -     } -}`
View Code

Come again, Hdu. 1398

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

The title says that a country's coins are square, and the face value is square.

There are 1 bucks, 4 bucks, 9 bucks, 16 bucks ... Up to 289 bucks (17^2)

There are several ways to make a sum of n dollars

AC Code:

`1#include <cstdio>2typedefLong LongLL;3 Const intN = -+5; 4 Const intMAX = -; 5 LL C1[n], c2[n];6 intN;7 voidinit () {8      for(inti =0; i < N; i + +) c1[i] =1;9      for(inti =2; I <= MAX; i + +){ Ten          for(intj =0; J < N; J + = i*i) { One              for(intK =0; J + K < N; K + +){  AC2[j + K] + =C1[k]; -             } -         }  the          for(intj =0; J < N; J + +){  -C1[J] =C2[j]; -C2[J] =0; -         } +     } - }  + intMain () { A init (); at      while(SCANF ("%d", &n)! = EOF &&N) { -printf"%i64d\n", C1[n]); -     } -}`
View Code

is to change some small places, are the template problem (o?ω?o)

So the parent function of ACM is finished (*. ∀. )

After that is the math of the mother function, do not want to see the person can end the content of this chapter (*. ∀. )

ACM NUMBER Theory Tour---mother function (also called generative function) (Pain and Happiness (╭￣3￣) ╭)

Related Keywords:

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.