The parent function is also called the generating function. The definition is given sequence: A0,A1,A2,....... ak,......, then function G (x) =a0+a1*x+a2*x2+......ak*xk called sequence A0,A1,A2,....... AK,...... The parent function (that is, the build function).
For example, the generating function for sequence 1,2,3.......N is: G (x) =x+2x2+3x3+........nxn. Click this link: Baidu Encyclopedia
Special when the sequence is: 1,1,1,1, .... 1, this generating function is: g (x) =x+x2+x3+.......+xn= (1-xn)/(1-x), when -1<x<1 G (x) =1/(1-x)
1/(1-x)n=1+c (n,1) x+c (n+1,2)x2+c (n+2,3)x3+...+c (n+k-1,k)xk+ ... You can restore the build function to an array.
=============================================================================================================== ===========
Example 1: Use the parent function to find the formula of the Fibonacci sequence. FIB (n) =fib (n-1) +fib (n-2), here assumes that the FIB (1) =1,fib (2) = 1;
The method of solving this recurrence relation is: ①, the recursive relation becomes the parent function equation, the ②, the solution of the female function equation, the ③, the female function becomes the power series form.
So the generation function of the Fibonacci sequence is: G (x) = x+x2+2x3+3x4+5x5+8x6 ....
Both sides of the equation are *x: XG (x) = x2+x3+2x4+3x5+5x6+8x7+ ....
Add: G (x) +xg (x) =x+2x2+3x3+5x4+8x5+13x6+ ...
We compare g (x) to get:g (x) +xg (x) =g (x)/x-1; So we can get:g (x) =x/(1-x-x2).
Can make: 1-x-x2=0, get two root for: a= (1-√5)/2,b= (1+√5)/2, so we can know: 1-x-x2= (x-x1) (x-x2) = (1-ax) ( 1-bx);
Assuming x/(1-x-x2) =m/(1-ax) +n/(1-BX),-Pass has: X=m (1-BX) +n (1-ax). The m=-1/√5,n=1/√5 is available by the coefficient relationship, so g (x) =-1/√5 (1-BX) +1/√5 (1-ax).
We know: 1/(1-BX) =1/[1-(1+√5)/2x] is a male ratio (1+√5)/2 geometric series, 1/(1-ax) is the male ratio (1-√5)/2 geometric series, so its general formula is: Fib (n) =1/√5[bn+1-a N+1].
=============================================================================================================== ===========
Example 2: If there are 1 grams, 2 grams, 3 grams, 4 grams of weight each one, what kinds of weight can be weighed? What are the possible options?
Constructs a parent function, if the weight is indicated by the exponent of X, then:
1 weights of 1 grams can be represented by the function 1+x, (the preceding 1 means 1 grams of weights 0)
1 2 grams of weights can be 1+x2 ,
1 3 grams of weights can be 1+x3 ,
1 4 grams of weights can be 1+x4 ,
Then the product of the combination of several weights is expressedas: (1+x) (1+x2) (1+x3) (1+x4) =1+x+x2+2x3+2x4+2x5+2x6+2x7+x8+x9+x10, the coefficient is the number of schemes .
Examples of items weighing 6 are: ①, 1,2,3;②, 2, 42 options.
=============================================================================================================== ===========
Example 3: 1 points, 2 points, 3 points of the stamps to put out the number of different numbers of programs?
This is the case with the above example: this stamp can be repeated. It is known that the generating function is : G (x) = (1+x+x2+ ...) (1+x2+x4+ ...) (1+x3+x6+ ...), the coefficient is the number of schemes after the co-rationale is expanded.
=============================================================================================================== ===========
Example 4: De Mechiriac weighing problem
(1) Weight for A1,a2,a3.....ak, how to put in the balance of the two ends, can be said to weigh n the different ways of the object is CN, then the parent function of CN is:
G (x) = (x-a1+1+xa1) (x-a2+1+xa2) ... (x-ak+1+xak)------ X-A1 said weight A1 and objects placed in the same pallet,xa1 that weights and objects placed in different trays, 1 is not the weight.
(2) Weights for A1,a2,a3....ak, such as can only be placed at one end of the balance, can be said to weigh n the different ways of the object is CN, then the parent function of CN:
G (x) = (1+xa1) (1+xa2) ... (1+Xak)
=============================================================================================================== ===========
Example 5: dividing integers into several integers (equivalent to placing n apples on n indistinguishable plates, each plate can be placed in multiple, or not), as mentioned in the previous blog post.
Assuming that 1 appears as the number of occurrences of a1,2 as the number of occurrences of A2.........K as AK, then the resulting function is:
g (x) = (1+x+x2+x3+x4+.....< Span style= "FONT-SIZE:14PX;" >) (1+x2+ x4+x6+x8+ ... 1+x3+x6+x9+ .... n )
front 1+x2+x4+x6+x8+ ... This means when a 2 o'clock appears for x2, when appears two 2 o'clock for x4. Why, when n is present, there are only two 1+xn
or the Nyist 90 (number division) as an example: this is the direct use of online templates
[CPP]View Plaincopyprint?
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- Using namespace std;
- const int max=50;
- #define CLR (Arr,val) memset (arr,val,sizeof (arr))
- int N,m,value[max],temp[max];
- int main ()
- {cin>>m;
- While (m--)
- {cin>>n;
- Fill (value,value+max,1); //value used to store coefficients
- CLR (temp,0); //temp used to keep every situation.
- For (int i=2;i<=n;i++)
- {for (int j=0;j<=n;j++)
- For (int k=0;k+j<=n;k+=i) //control the change of each coefficient and the maximum number of entries per number
- TEMP[K+J]+=VALUE[J];
- For (int j=0;j<=n;j++)
- value[j]=temp[j],temp[j]=0;
- }
- cout<<value[n]<<endl;
- }
- return 0;
- }
=============================================================================================================== ===========
Example 2:hdu 1085 (coin problem)
[CPP]View Plaincopyprint?
- There are 3 denominations of 1, 2, 5 coins, enter 3 numbers for each coin of the number of pieces, to find the smallest can not be composed of these coins of the denomination is how much?
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- Using namespace std;
- const int max=8010;
- #define CLR (Arr,val) memset (arr,val,sizeof (arr))
- int value[max],temp[max],num[3],coin[3]={1,2,5};
- int main ()
- {while (cin>>num[0]>>num[1]>>num[2])
- { if (num[0]+num[1]+num[2]==0) break ;
- int max=num[0]+2*num[1]+5*num[2];
- CLR (value,0);
- CLR (temp,0);
- Fill (value,value+num[0]+1,1);
- For (int i=1;i<3;i++)
- {for (int j=0;j<=max;j++)
- For (int k=0;k+j<=max&&k/coin[i]<=num[i];k+=coin[i])//Note cannot exceed the number
- TEMP[K+J]+=VALUE[J];
- For (j=0;j<=max;j++)
- value[j]=temp[j],temp[j]=0;
- }
- For (i=0;i<=max+1;i++)//Traversal
- if (value[i]==0) {cout<<i<<endl; break;}
- }
- return 0;
- }
Related to the parent function of the topic are: HDU 1171,1398,1709,2065,2069,2082,2152;poj 3046,3716,3734 and so on ~ have time to do, there are a lot of things do not understand, should be first summed up the other knowledge ~ ~
Mother function Detailed explanation