HDOJ 2643 第二类斯特林数

链接:

http://acm.split.hdu.edu.cn/showproblem.php?pid=2643

题意:

n位选手参加比赛,每个选手有一个排名,有可能有并列,那么排名情况有多少种可能?

题解:

n位选手参加比赛,每个选手有一个排名,有可能有并列,那么排名情况有多少种可能? 
n位选手可以放到1个集合,两个集合。。。。n个集合,因为每个集合对应的是名次,所以集合是区分的。 
那么对于n个选手,可以选择的方案数: 
ni=1S2,(n,i)i!

代码:

31 const int mod = 20090126;
32 ll stir[MAXN][MAXN];
33 ll fac[MAXN];
34 
35 void init() {
36     rep(i, 1, MAXN) {
37         stir[i][1] = stir[i][i] = 1;
38         rep(j, 1, i)
39             stir[i][j] = (stir[i - 1][j - 1] + j*stir[i - 1][j]) % mod;
40     }
41     fac[1] = 1;
42     rep(i, 2, MAXN) fac[i] = i*fac[i - 1] % mod;
43 }
44 
45 int main() {
46     ios::sync_with_stdio(false), cin.tie(0);
47     init();
48     int T;
49     cin >> T;
50     while (T--) {
51         int n;
52         cin >> n;
53         ll ans = 0;
54         rep(i, 1, n + 1) ans = (ans + fac[i] * stir[n][i]) % mod;
55         cout << ans << endl;
56     }
57     return 0;
58 }
posted @ 2017-10-02 22:28  Flowersea  阅读(140)  评论(0编辑  收藏  举报