Integer Division (various types) nyist 571

Source: Internet
Author: User
Tags integer division

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].

Previously, I excerpted others. I did a good job writing it, so I don't have to write it myself ...... The following division is what I thought when I was working on nyist 571. I only talked about the first several division and the odd Division. I didn't need to write any even division, the division of odd numbers is similar to that of even numbers. I believe that the Division of even numbers is not a problem!

3. Divide N into several odd or even sum:

F (n, k) indicates dividing N into the sum of odd numbers not greater than K.

When k = 1 or k = 2, the odd number can be divided into only 1, so the number can only be one.

When K> N, the excess parts cannot be divided, so the species are f (N, N ).

When K = N, consider the parity of n. If it is an odd number, it is a division (even numbers do not need to be considered ), then add the odd number smaller than N.

When K is less than N, consider the parity of K, and then consider the situation that does not include K.

For details, refer to the F3 function in the code.

 

You must have your own ideas. You must never remember other people's things !!! You may be able to come up with a better solution. Come on !!!!

 

# Include <iostream> using namespace STD; int F1 (int n, int K) {If (n = 1 | K = 1) return 1; if (k> N) return F1 (n, n); If (n = k) return 1 + F1 (n, k-1); Return F1 (n-k, K) + F1 (n, k-1); // contains m and does not contain m} int F2 (int n, int K) {If (k = 1 | n = K) return 1; if (k> N) return 0; return F2 (n-k, k) + F2 (n-1, k-1 ); // contains 1 and does not include 1} int F3 (int n, int K) // It indicates an odd number Division not greater than K {If (k = 1 | K = 2) return 1; // there is only one case: N 1 If (n = k) if (N % 2) return 1 + F3 (n, K-2 ); // n is an odd number: itself + El with an odd number less than N Se return F3 (n, k-1); // n is an even number: an odd number less than N is divided if (n <k) return F3 (n, n); If (K % 2) return F3 (n-k, k) + F3 (n, K-2); // n is an odd number: else return F3 (n, k-1); // n is an even number: Odd Division without k} int F4 (int n, int K) {If (k = 1 & n = 1) return 1; if (k = 1 & n> 1) return 0; If (k> N) return F4 (n, n); If (k = N) return 1 + F4 (n, k-1); Return F4 (n-k, k-1) + F4 (n, k-1); // contains K without K and is different, so k-1} int main (void) {int N, K; while (CIN> N> K) {cout <F1 (n, n) <Endl; // divide N into a maximum of K Number of shards. Cout <F2 (n, k) <Endl; // Number of partitions that divide N into the sum of K positive integers cout <F1 (n, k) <Endl; // divide N into partitions whose maximum number cannot exceed K. Cout <F3 (n, n) <Endl; // divide N into the sum of several odd positive integers. Cout <F4 (n, n) <Endl; // divide N into the sum of several different integers. }}

 

 

 

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.