Question: a positive integer N is expressed as the sum of a series of positive integers. There are several division methods.
N = N1 + N2 + N3 +... + NK (N1> = N2> = N3....> = 1, k> = 1)
It is called a division of positive integers. Positive integer N may have different divisions. For example, all the divisions of positive integer 6 are
6 = 6
6 = 5 + 1
6 = 4 + 2 6 = 4 + 1 + 1
6 = 3 + 3 6 = 3 + 2 + 1 6 = 3 + 1 + 1 + 1
6 = 2 + 2 + 2 6 = 2 + 2 + 1 + 1 6 = 2 + 1 + 1 + 1 + 1
6 = 1 + 1 + 1 + 1 + 1 + 1
Method: Find the recurrence formula:
# Include <iostream>
Using STD: cout;
Using STD: Endl;
Using STD: CIN;
Int partition (int abc, int max) // Max indicates the maximum positive integer in the partitioned positive integer
{
If (ABC = 1 | max = 1)
{
Return 1;
}
If (ABC <max)
Return partition (ABC, ABC );
If (ABC = max)
Return partition (ABC, abc-1) + 1;
If (ABC> MAX)
Return partition (ABC, max-1) + partition (ABC-Max, Max); // consists of two parts: one is represented by the max-1; the other is represented by the Max, it can be converted to the ABC-Max representation type.
}
Int main ()
{
Int ABC;
While (CIN> ABC)
Cout <partition (ABC, ABC) <Endl;
}