Algorithm Course-Recursive (integer division problem)

Source: Internet
Author: User
Tags integer division

"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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.