"Example 2-5" integer division Problem
In all the different divisions of positive integer n, the maximum addend N1 is not greater than the number of partitions of M Q (n,m). The following recursive relationships can be established for Q (N,M).
(1) q (n,1) =1,n≥1
When the maximum addend N1 is not greater than 1 o'clock, any positive integer n has only one form, namely n=1+1+...+1. (n 1)
(2) Q (n,m) =q (n,n), m≥n
The maximum addend N1 is actually not greater than N. So Q (1,m) =1.
(3) Q (n,n) =1+q (n,n-1)
The Division of Positive integer n is composed of the division of N1=n and the division of N1≤n-1.
(4) Q (n,m) =q (n,m-1) +q (n-m,m), n>m>1
The maximum addend n1 of positive integer n is not greater than M, which consists of the Division of N1=m and the division of N1≤m-1.
Proof: (a) The case that the division contains m, that is {m,{x1,x2,..., XI}, where {x1,x2,..., XI} and is n-m, may appear again m, all the number of divisions is Q (n-m,m).
(b) The division does not contain the case of M, then all the values in the division are smaller than m, i.e. N (m-1) division, the number is Q (n,m-1);
So Q (n,m) =q (n-m,m) +q (n,m-1);
The above relationship actually gives the recursive formula for calculating Q (n,m) as follows:
int q (int n,int m)
{
If ((n=1) | | | (m<1)) return 0;
If ((n==1) | | | (m==1)) return 1;
If (n<m) return Q (n,n);
If (n==m) return 1+q (n,n-1);
Return Q (n,m-1) +q (n-m,m);
}
Algorithm Course-Recursive (integer division problem)