HDU 2643
/*
The second type of Stirling is the number of methods that divide a set containing n elements into k non-empty subsets.
Recurrence formula:
S (n, k) = 0 (n <k | K = 0 ),
S (n, n) = S (n, 1) = 1,
S (n, k) = S (n-1, k-1) + KS (n-1, K ).
*/
# Include <stdio. h> # define ll long # define Nmax 101 # define nnum 20090126 llll num [Nmax] [Nmax], FAC [Nmax]; void Init () {int I, J; for (I = 1, FAC [0] = 1; I <Nmax; I ++) {FAC [I] = FAC [I-1] * I % nnum ;} for (I = 1; I <Nmax; I ++) {num [I] [1] = 1; num [I] [0] = 0 ;} for (I = 2; I <Nmax; I ++) {for (j = 1; j <Nmax; j ++) {if (I = J) {num [I] [I] = 1 ;} else {num [I] [J] = (Num [I-1] [J-1] + num [I-1] [J] * j) % Nnum ;}}} int main () {# ifndef online_judgefreopen ("in. data "," r ", stdin); # endifinit (); int t, n, I; ll res; while (scanf (" % d ", & T )! = EOF) {While (t --) {scanf ("% d", & N); for (I = 1, Res = 0; I <= N; I ++) {res + = num [N] [I] * FAC [I]; Res % = nnum;} printf ("% i64d \ n", Res );}} return 0 ;}
HDU 2512
# Include <stdio. h> # define Nmax 2001 # define nnum 1000int num [Nmax] [Nmax]; void Init () {int I, j; for (I = 1; I <Nmax; I ++) {num [I] [0] = 0, num [I] [1] = 1 ;}for (I = 2; I <Nmax; I ++) {for (j = 1; j <Nmax; j ++) {if (I = J) {num [I] [I] = 1; continue ;} num [I] [J] = (Num [I-1] [J-1] + num [I-1] [J] * j) % nnum ;}}} int main () {# ifndef online_judgefreopen ("in. data "," r ", stdin); # endifint n, x, I, Res; Init (); Wh Ile (scanf ("% d", & N )! = EOF) {While (n --) {scanf ("% d", & X); for (I = 1, Res = 0; I <= x; I ++) {res + = num [x] [I]; Res % = nnum;} printf ("% d \ n", Res) ;}} return 0 ;}
TIPS:
Bell number, also known as Bell number.
Eric temple bell is the name of Eric temple bell.
B (n) is the number of division methods for a set containing n elements.
B (0) = 1, B (1) = 1, B (2) = 2, B (3) = 5,
B (4) = 15, B (5) = 52, B (6) = 203 ,...
Recursive Formula,
B (0) = 1,
B (n + 1) = sum (0, n) C (n, k) B (k). n = 1, 2 ,...
Sum (0, n) indicates the sum of K from 0 to N, C (n, k) = n! /[K! (N-k)!]
-------------------------
The Stirling Number, also known as the strling number.
In composite mathematics, Stirling numbers can refer to two types of numbers, both proposed by James Stirling, A 18-century mathematician.
The first Stirling number is positive and negative, and its absolute value is the number of methods for dividing a set of n elements into k rings.
Recursive Formula,
S (n, 0) = 0, S (1, 1) = 1.
S (n + 1, K) = S (n, k-1) + NS (n, k ).
The second type of Stirling is the number of methods that divide a set containing n elements into k non-empty subsets.
Recursive Formula,
S (n, n) = S (n, 1) = 1,
S (n, k) = S (n-1, k-1) + KS (n-1, K ).
Put N balls with Different balls into k unlabeled boxes (n> = k> = 1, and the box cannot be blank. (that is, the number of cases where a set containing n elements is divided into k sets)
Recurrence formula:
S (n, k) = 0 (k> N)
S (n, 1) = 1 (k = 1)
S (n, k) = 1 (n = K)
S (n, k) = S (n-1, k-1) + K * s (n-1, k) (N> = k> = 2)
Analysis: There are n Different balls, which are represented by B1, B2,... and bn respectively. Obtain a ball bn from it. There are two kinds of BN placement methods:
1. BN exclusive box, then the remaining ball can only be placed in the K-1 box, the number of S (n-1, k-1 );
2. bn shares a box with other balls, so b1, b2 ,..., the n-1 balls of the bn-1 are placed in K boxes, and the BN is placed in one of the boxes. The number of balls is K * s (n-1, m ).
-------------
The relationship between the number of Bell and the number of Stirling is,
Each bell number is the sum of the Second Stirling number.
B (n) = sum (1, N) S (n, k ).
References:Http://planetmath.org /? OP = getobj & from = objects & id = 9059