Integer Division-a dynamic planning of problems in the old growth talk

Source: Internet
Author: User
Tags integer division

Integer Division-an old growth point:
1) Practice and combine mathematical capabilities.
2) practice recursive thinking
3) practice DP
In short, it is a classic topic that can no longer be classic:
This is a good question:
1. Divide N into the sum of several positive integers.
2. Divide N into the sum of K positive integers.
3. Divide N into partitions whose maximum number cannot exceed K.
4. Divide N into the total number of groups of certain odd positive integers.
5. Divide N into the sum of several different integers.

 

1. Divide N into criteria not greater than m:

 1). If multiple integers are divided, they can be the same:

DP [N] [m] = DP [N] [M-1] + dp [n-M] [m] DP [N] [m] indicates the division of integer n, the number of partitions where each number is not greater than M.
The number of partitions can be divided into two types:
A. Each number of partitions is smaller than m, which is equivalent to a number not greater than m-1. Therefore, the number of partitions is DP [N] [M-1].
B. the number of partitions is M. then subtract m from N, and the rest is equivalent to dividing N-M. Therefore, the number of partitions is DP [n-M] [M].

2). If multiple integers are divided:

DP [N] [m] = DP [N] [M-1] + dp [n-M] [M-1] DP [N] [m] indicates the division of integer n, the number of partitions where each number is not greater than M.
The same division can be divided into two situations:
A. Each number in the Division is smaller than m, which is equivalent to a number not greater than m-1, and the number of partitions is DP [N] [M-1].
B. The number of partitions is M. Subtract m from N, and n-M is divided,

In addition, each number is not greater than the value of s-1. Therefore, the number of partitions is DP [n-M] m-1].

2.Division of N into k numbers:

    DP [N] [k] = DP [n-k] [k] + dp [n-1] [k-1];

Methods can be divided into two types:
Category 1: N parts do not contain 1 division. To ensure that each part is greater than or equal to 2, K points can be obtained first.
And then divide the remaining n-k into k parts. The methods include DP [n-k] [K].
Category 2: There must be at least one division in N portions. You can first extract one portion as a separate portion, with the remaining portion.
The N-1 under can be further divided into k-1 parts, the method is: DP [n-1] [k-1]

  

 3. Divide N into several odd-number Division Methods: (do not understand)

G [I] [J]: divides I into J even numbers.

F [I] [J]: divides I into J odd numbers.
G [I] [J] = f [I-j] [J];
F [I] [J] = f [I-1] [J-1] + G [I-j] [J];

 

Thank you for your explanation ~

The Code is as follows:

/*
* Hit1402.c
*
* Created on: 2011-10-11
* Author: bjfuwangzhu
*/

# Include <stdio. h>
# Include <string. h>
# Define Nmax 51
Int num [Nmax] [Nmax]; // divides I into numbers not greater than J.
Int num1 [Nmax] [Nmax]; // divides I into numbers not greater than J
Int num2 [Nmax] [Nmax]; // divides I into J numbers.
Int f [Nmax] [Nmax]; // divides I into J odd numbers.
Int G [Nmax] [Nmax]; // divides I into J Even Numbers
Void Init (){
Int I, J;
For (I = 0; I <Nmax; I ++ ){
Num [I] [0] = 0, num [0] [I] = 0, num1 [I] [0] = 0, num1 [0] [I] = 0, num2 [I] [0] =
0, num2 [0] [I] = 0;
}
For (I = 1; I <Nmax; I ++ ){
For (j = 1; j <Nmax; j ++ ){
If (I <j ){
Num [I] [J] = num [I] [I];
Num1 [I] [J] = num1 [I] [I];
Num2 [I] [J] = 0;
} Else if (I = J ){
Num [I] [J] = num [I] [J-1] + 1;
Num1 [I] [J] = num1 [I] [J-1] + 1;
Num2 [I] [J] = 1;

} Else {
Num [I] [J] = num [I] [J-1] + num [I-j] [J];
Num1 [I] [J] = num1 [I] [J-1] + num1 [I-j] [J-1];
Num2 [I] [J] = num2 [I-1] [J-1] + num2 [I-j] [J];
}
}
}
F [0] [0] = 1, G [0] [0] = 1;
For (I = 1; I <Nmax; I ++ ){
For (j = 1; j <= I; j ++ ){
G [I] [J] = f [I-j] [J];
F [I] [J] = f [I-1] [J-1] + G [I-j] [J];
}
}
}
Int main (){
# Ifndef online_judge
Freopen ("data. In", "r", stdin );
# Endif
Int N, K, I, res0, RES1, RES2, RES3, res4;
Init ();
While (~ Scanf ("% d", & N, & K )){
Res0 = num [N] [N];
RES1 = num2 [N] [k];
RES2 = num [N] [k];
For (I = 0, RES3 = 0; I <= N; I ++ ){
RES3 + = f [N] [I];
}
Res4 = num1 [N] [N];
Printf ("% d \ n", res0, RES1, RES2, RES3, res4 );
}
Return 0;
}

Divide a positive integer into the sum of consecutive positive integers.
For example, 15 can be divided into four forms of continuous integer addition:
15
7 8
4 5 6
1 2 3 4 5

First consider the general form, set N to the positive integer to be divided, and X to the smallest integer after division. If n has a division, then
The result is X. If there are two types of division, X and x + 1. If there are m types, is x, x + 1, x + 1 x + 2 ,..., x + 1 x + 2... X + m-1
Add each result to obtain a formula (I * x + I * (I-1)/2) = n, and I is the number of integers added after the current division.
The Division that satisfies the condition is all the conditions that make X a positive integer.
In the above example, when I = 1, it is divided into a positive integer, x = 15, and when I = 2, x = 7.
If X = 3, x = 4, and X = 4, 4/9 is not a positive integer. Therefore, 15 cannot be divided into four integers.
When x = 5, x = 1.

There is another question: what is the maximum I value? However, it must be smaller than N. We can make a hypothesis,
Assume that N can be split into a division with a minimum value of 1. In the preceding example, 1 2 3 4 5. This is the maximum number of N. If this assumption is not met,
Then I must be smaller than the number of positive integers in this division. Therefore, we can obtain the formula I * (I + 1)/2 <= N, that is, when I satisfies
In this formula, N can be divided.

The Code is as follows:

void split(int n) {
int i, j, te, x, xlen;
for (i = 1, xlen = 0; (te = i * (i - 1) / 2) < n; i++) {
x = n - te;
if (x % i == 0) {
x /= i;
printf("%d", x);
for (j = 1; j < i; j++) {
printf("%d ", x + j);
}
printf("\n");
xlen++;
}
}
printf("%d\n", xlen);
}

 

The following are reprinted:

Returns the product of the largest division factor.
Problem description: given a positive integer n, a division with the maximum product of the factor and the product are obtained in all the divisions of N. Example: 8 = {8}, {7, 1}, {6, 2}, {5, 3}, {4, 4}, {3, 3, 2 }, {2, 2, 2, 2}, among which the product of 3*3*2 is the largest, so the entire division is output.
The product 18.
Algorithm Analysis: this is a problem I have seen on a forum and a mathematical analysis of the problem. The following is a simple example:
(1) for any positive integer m greater than or equal to 4, there is a division M = m1 + m2, so that M1 * M2> = m certificate: Make M1 = int (M/2 ), then M1> = 2, M2 = m-m1; then m2> 2, and M2> = m/2> = m1; m1 * M2> = 2 * M2> = m; certificate completion;
The proof is simply: for a positive integer m greater than or equal to 4, there is a two-partition factor, and the product of these two factors is always not less than the original number M itself.
(2) from (1) The number can finally be divided into 2 ^ r * 3 ^ s. Proof r <= 2;
Evidence: If R> 2, at least three factors are 2, and 2*2*2 <3*3;
Therefore, we can replace the three two factors with two factors 3. The product is larger and the result is verified.
In summary (1) and (2), there are: Any factor greater than 4 can be better decomposed, and 4 can be decomposed into 2*2.
Therefore, this number should be divided into 2 ^ K1 * 3 ^ K2. It can also prove that K1> = 0 and k1 <= 2, so:
A. When n = 3 * r, It is decomposed into 3 ^ r.
B. When n = 3 * r + 1, it is decomposed into 3 ^ (r-1) * 2*2
C. When n = 3 * r + 2, it is decomposed into 3 ^ r * 2.
The remaining programming processing is too simple. The first is to process the special situations of <= 4, and then judge the three cases of Model 3 in case of> 4, and finally output them one by one. It can be seen that mathematics has a strong function in integer division. Who is this question called integer division? It's strange not to be close to mathematics! ^_^.

 

Grade 6 Olympiad-integer division (useful conclusion)

Example 1: Split 14 into the sum of several natural numbers and then obtain the product of these numbers. How should we split 14 to maximize the product? What is the maximum product?

Analysis and Solution: we should first consider the product of which values can be as big as possible.
First, the number cannot be 1, which is obvious.
Secondly, there cannot be a number greater than 4 in the number to be divided. Otherwise, the number can be split into two and the sum of the other. The product of the two numbers must be greater than the original number, for example, 7 is smaller than the product of 2 and 5.
Again, because 4 = 2 × 2, we can only consider splitting the score into 2 and 3.
Note that 2 + 2 + 2 = 6 2 × 2 × 2 = 8; 3 + 3 = 6 3 × 3 = 9. Therefore, if there are three 2 in the number, it is better to replace it with two three. In other words, there can be at most two in the number, and the rest are three. According to the above discussion, we should split 14 into the sum of four 3 and one 2, that is, 14 = 3 + 3 + 3 + 3 + 2, the accumulation of these five numbers has a maximum value of 3x3x3x3x2 = 162.
To promote the above conclusions, the general situation is:
Split natural number S (S> 1) into several natural numbers and: S = A1 + A2 +... + An, when A1, A2 ,..., There are at most two 2 in an. When the remaining three are, the product M = a1a2... An has a maximum value.

Example 2: Divide 1993 into several unequal natural numbers and make the product of these natural numbers the maximum. What is the product?
Solution: the division of 1993 into several distinct natural numbers has only a limited number of division methods, so there must be a division that maximizes the product of these natural numbers.
If 1 is used as a factor, the product is obviously not the largest. Divide 1993 into several natural numbers that are not equal to each other. The greater the number of factors, the greater the product. To make the number of factors as many as possible, we divide 1993 into 2 + 3... + N until and greater than 1993.
If the sum is 1 greater than 1993, the number of factors should be reduced by at least one. To maximize the product, remove the minimum 2 and add the last number (maximum) to 1.
If the sum is greater than 1993 K (k = 1), remove the number equal to K to maximize the product.
So n = 63. Because 2015-1993 = 22, we should remove 22 and divide 1993 into (2 + 3 +... + 21) + (23 + 24 +... + 63)

In this form, the product of these numbers is the largest, and its product is 2 × 3 ×... × 21 × 23 × 24 ×... * 63.

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.