What is a female function? I still consult the Baidu Encyclopedia.
definition: for any sequence of a0,a1,a2...an the following method is associated with a function: ~g (x) = a0 + a1x + a2x^2 + a3x^3 +....+ anx^n is called G (x) is the generating function of the sequence (generating function) Example: A (x) = (1+x) ^n~c (n,0), C (n,1), C (n,2), C (n,3),....., C (n,n) I understand the parent function is this meaning:
For example, there are two types of banknotes: $1 and $5, two and three respectively. There are several cases of their total combination.
(1+2x) * (1+3x^5).
To explain (1+2X), the index of x refers to a 1 dollar note, and its X Factor is the number of ways to take its 1 yuan (or exponent). The formula can also be explained in this way.
Then there is the algorithm of the mother function. The idea of a backpack is in it, first put the first formula (also can be understood as the first case) into the backpack c1[i]. I means to take I have c1[i] method, the general initial is 1 kinds. C1[0] also be aware of initializing to 1. Then start the backpack processing from the second formula, which can be stuffed into the backpack plus the number of previous cases. Temporarily open an array to hold the data, that is, c2[k+j]+=c1[j]. Each addition is updated to C1 and the C2 zeroed.
#include <iostream>
#include <stdio.h>
using namespace std;
int main ()
{
int N;
int c1[125],c2[125];
while (Cin>>n)
{
int i,j,k;
for (i=0;i<=n;i++)//Initialize the coefficient of the first expression
{
c1[i]=1;
c2[i]=0;
}
for (i=2;i<=n;i++)
{//starts with the second expression because there are no restrictions, so there are N expressions for
(j=0;j<=n;j++)
{// An expression from the multiplicative expression first to the last
if (c1[j])//This is the one I added for
(k=0;k+j<=n;k+=i)
{//k is the exponent of the J variable, and the first expression accumulates I
c2[j+k]+=c1[j];
}
}
The for (j=0;j<=n;j++)
{//scroll array is updated once after an expression has been calculated
C1[j]=c2[j];
c2[j]=0;
}
}
printf ("%d\n", C1[n]);
}
return 0;
}