Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=2512
Main topic:
There are n cards, the n card is divided into several different sets, the collection cannot be empty. Q: How many kinds of sub-methods are there altogether?
Ideas:
Reference post: http://blog.csdn.net/acm_cxlove/article/details/7857671
The number of collections can be 1, 2, 3 、...、 N. The problem changed to put n cards in the I set.
This time a combinatorial problem can be solved with the second type of Stirling number.
S (p,k) = S (p-1,k-1) + k*s (p-1,k);
Represents the number of elements of p that are placed in a K-indistinguishable set and not empty.
The solution of the problem is: Σs (P,i), (1 <= i <= P). This number becomes the bell number.
The bell number is the number of divisions of the P-element set into non-null and indistinguishable examples.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;int Stir[2010][2010],bell[2010];int Main () {for (int i = 1; i <=; ++i) stir[i][1] = stir[i][i] = 1;
for (int i = 2; I <=; ++i) {for (int j = 2; J <= i; ++j) stir[i][j] = (Stir[i-1][j-1] + stir[i-1][j ]*J)%1000; } for (int i = 1; I <=, ++i) for (int j = 1; J <= i; ++j) bell[i] = (Bell[i] + stir[i][j])% 1000;
int n,t; Cin >> T; while (t--) { cin >> N; cout << Bell[n] << Endl; } return 0;}
HDU2512 Cartoon Adventure "Stirling number, Bell number"