Hdu 2512 一卡通大冒险 (贝尔数)

来源:互联网 发布:windows apache 安装 编辑:程序博客网 时间:2024/04/26 04:35

Bell数是将P个元素集合分到非空且不可区分的子集的划分个数

性质详见 贝尔数 - 维基百科,自由的百科全书

每个贝尔数都是"第二类Stirling数"的和

关于斯特林数:斯特林数 - 环排列 学习小记 Hdu 3625 Examining the Rooms + LightOJ 1326 Race - whyorwhnt的专栏

#include <cstdio>const int N=2005;const int mod=1000;int stir2[N][N];int bell[N];void Init (){    int i,j;    for (i=1;i<=2000;i++)    {        stir2[i][0]=0;        stir2[i][i]=1;        for (j=1;j<i;j++)            stir2[i][j]=(stir2[i-1][j-1]+j*stir2[i-1][j])%mod;    }    for (i=1;i<=2000;i++)    {        bell[i]=0;        for (j=0;j<=i;j++)            bell[i]=(bell[i]+stir2[i][j])%mod;    }}int main (){    Init ();    int T,n;    scanf("%d",&T);    while (T--)    {        scanf("%d",&n);        printf("%d\n",bell[n]);    }    return 0;}