Common parent function
1. Get the parent function (Generate function) according to the topic requirement
2. Assign the coefficients of the expression of the first parenthesis to C1.
3. Start with the second parenthesis to calculate the product of each item.
4. Iterate to get the result of the final parent function.
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace STD;intc1[1100],c2[1100];inta[1100];intMain () {intT,n,k;Cin>> T; while(t--) {Cin>> N >> K;memsetA0,sizeof(A)); for(inti =1; I <= K; ++i) {intb;Cin>> a >> b; A[a] = b; } for(inti =0; I <= N; ++i) C1[i] = c2[i] =0; c1[0] =1; for(inti =1; I <= K; ++i)//I-Expressions (1+x^2+ ...){ for(intj =0; J <= N; ++J)//Front I expression multiplicative expression (previous expression) in the first J variable{/ * such as (1+x) (1+x^2) (1+x^3), J first indicates the coefficients of 1 and X, the i=2 becomes (1+x+x^2+x^3) after execution, when J should indicate the coefficients of the four variables of the first parenthesis after merging. */ for(intK =0; J+i*k <= N && k <= A[i]; ++K) C2[j+i*k] + = c1[j];//c2[] Save results}The //k represents each of the expressions that will be evaluated. (Since the increment of the I-expression is I, the k increases each time I). for(intj =0; J <= N; ++J) {C1[j] = c2[j];//IterationC2[J] =0; } }cout<< C1[n] << Endl; }return 0;}
Exponential type female function
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace STD;DoubleF[] = {1,1,2,6, -, -,720,5040,40320,362880,3628800};Doublenum[ One],c1[ One],c2[ One];intMain () {intN,m; while(Cin>> N >> M) {memset(C1,0,sizeof(c1));memset(C2,0,sizeof(C2)); for(inti =0; i < N; ++i)Cin>> Num[i]; for(inti =0; I <= num[0]; ++i) C1[i] =1.0/f[i]; for(inti =1; i < N; ++i) { for(intj =0; J <= M; ++J) for(intK =0; K <= Num[i] && (k+j) <=M; ++K) C2[k+j] + = (c1[j]/f[k]); for(intj =0; J <= M; ++J) {C1[j] = c2[j]; C2[J] =0; } }Doubles =1.0*C1[M]*F[M];printf("%.0lf\n", s); }return 0;}
Parent function "Template"