Basic code template for a parent function
Self-understanding: for (#式) (1+x+x^2+x^3+x^4+x^5+ ...) * (1+x^2+x^4+x^6+x^8+x^10+ ....) * (1+x^3+x^6+x^9+x^12 ....) .....
The first for C1 and C2, put the first parenthesis of the above # (1+x+x^2+x^3+x^4+x^5+ ...). The coefficients are placed in the C1,
Thus again the calculation begins with the second parenthesis of the #, so i is the number of parentheses representing the #-type ,
The program simulates the manual calculation by first calculating the first parenthesis and the second parenthesis, and putting the results in the C2.
In the calculation of the result with the third bracket, the result is placed in the C2, and the fourth bracket is calculated, ....
So J means the coefficients of the calculated items , such as 1+x+x^2+x^3+x^4+x^5+ after the first time ..., j=0 points to 1,
j=2 points to X, ...., and K means the item in the bracket to be computed , because the first bracket, the exponent is 0, I, 2i .... So k to + i;
and results c2[j+k] + = c1[j]; is to multiply the coefficients of the calculated J item by the K term of the parentheses that are now being computed, so the exponent is j+k, so the result is put into c2[j+k], and that's the purpose of these for!
Finally refresh the results, the next set of data calculation!
C1[n] holds the coefficients before Xn, which is the number of n (A1,..., an) combinations
//integer split template#include <iostream>using namespacestd;Const intlmax=10000;//C1 is used to store the coefficients of the expansion, while the C2 is used for the calculation of the saved,//he uses subscripts to control the position of each item, for example C2[3] is the coefficient of x^3. //save with C1, then use C2 to save the changed values when calculating. intc1[lmax+1],c2[lmax+1];intMain () {intN, I, J, K; //the method of calculation is also the simulation of manual operation, the calculation of a parenthesis in parentheses,//In the past while(cin>>N) {//for 1+x+x^2+x^3+, all their coefficients are 1.//and C2 All is initialized to 0 is because later to use c2[i] + = x; for(i=0; i<=n; i++) {C1[i]=1; C2[i]=0; } //The first loop is a total of n parentheses, and I've already counted one.//so it's from 2 to n . for(i=2; i<=n; i++) { //The second loop is to put each one inside each parenthesis, with the previous//each of the parentheses inside the calculation. for(j=0; j<=n; J + + ) //The third level of parentheses is to control the proportion of X added in each item.//This is why you should use k+= i; for(k=0; k+j<=n; k+=i) {//merging similar terms, their coefficients to be added together, so is the addition, hehe. //I got stuck here when I first saw it. c2[J+k] + = c1[J];//because the exponent of the term k is constant at 1, so the coefficients of an item with an exponent of k+j are multiplied after the term of the exponent J, and the coefficients of the items of the index are added to the coefficient of the item of the J exponent. } //Refresh the data and proceed to the next calculation, which is the next parenthesis. for(j=0; j<=n; J + +) {C1[j]=C2[j]; C2[J]=0 ; }} cout<<c1[n]<<Endl; } return 0;}//this sentence c2[j+k] + = C1[j], the understanding of their own good experience Ah!
Basic template explanation of the parent function