[Combined mathematics] Class 1, Class 2 Stirling number, Bell number

Source: Internet
Author: User

I. The second type of Stirling number

Theorem: The second type of Stirling number S (p, k) counts the number of Division of the p element set into k undistinguished boxes without empty boxes.

Proof: it is not important for elements to take some boxes. The only thing that matters is what is installed in each box, no matter which box is loaded.

Recursive formulas include: S (p, p) = 1 (p> = 0) S (p, 0) = 0 (p> = 1) S (p, k) = k * S (P-1 k) + S (PM, K-1) (1 <= k <= PM ). Consider the first p positive integer, 1, 2,... p as the set to be divided

{1, 2,... p} is divided into k non-empty and non-differentiated boxes in two cases:

(1) those which make p separate in a box, there are S (P-1 K-1) division number

(2) the division that makes p not separate in a box exists with k * S (P-1 k) division numbers.

In the second case, p is not in a single box, that is, p and other elements are in a set, that is, before p is put, p-1 has been divided into k non-empty and undistinguished boxes.

The number of Shards is S (MA-1, k). Now the question is which box should p be put in. There are k options, so k * S (P-1 k) exists ).

Template:

Long s [maxn] [maxn]; // Stirling number required for storage const long mod = 1e9 + 7; // modulo void init () // preprocessing {memset (s, 0, sizeof (s); s [1] [1] = 1; for (int I = 2; I <= maxn-1; I ++) for (int j = 1; j <= I; j ++) {s [I] [j] = s [i-1] [j-1] + j * s [i-1] [j]; if (s [I] [j]> = mod) s [I] [j] % = mod ;}}

Note: Use the long type. If the number of elements is greater than 20, the value of the int type is exceeded.

Extension: k! * S (p, k) counts the number of bins that divide the p element set into k differentiated boxes without empty boxes.

 

II. Number of Bell

Theorem: Bell number B (p) refers to the number of bins that divide the p element set into non-empty and non-differentiated boxes (not in a few boxes ).

B (p) = S (p, 0) + S (p, 1) +... + S (p, k)

Therefore, for the number of Bell, the second type of Stiring must be obtained first.

III. First Stirling number

Theorem: The First Stirling number s (p, k) counts the number of methods that arrange p objects in k non-empty loops.

Proof: The circular arrangement in the preceding theorem is called a circle. Recurrence formula:

S (p, p) = 1 (p> = 0) there are p and p circles, and each circle has only one person

S (p, 0) = 0 (p> = 1) if at least one person exists, any arrangement should contain at least one circle.

S (p, k) = (P-1) * s (PM, k) + s (PM, K-1)

The person was marked as 1, 2,... p. There are two situations in which the p individual is arranged into k circles. The first sorting method is only p in a circle of the people themselves, the sorting method has s (1, K-1. In the second sort method, p should at least be in the same

In a circle. You can sort the values of 1, 2 .... p-1 is arranged in k circles and then p is placed in 1, 2 .... the left side of any person in type 1-1 is obtained. Therefore, the second type of sorting method is p-1) * s (P-1, k.

In proof, what we do is to divide {1, 2,..., p} into k non-empty and non-differentiated boxes, and then arrange the elements in each box in a circular arrangement.

Template:

Long s [maxn] [maxn]; // The first Stirling number required for storage. const long mod = 1e9 + 7; // modulo void init () // preprocessing {memset (s, 0, sizeof (s); s [1] [1] = 1; for (int I = 2; I <= maxn-1; I ++) for (int j = 1; j <= I; j ++) {s [I] [j] = s [i-1] [j-1] + (i-1) * s [i-1] [j]; if (s [I] [j]> = mod) s [I] [j] % = mod ;}}


 

      

[Combined mathematics] Class 1, Class 2 Stirling number, Bell number

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.