Bell数的定义:第n个Bell数表示集合{1,2,3,...,n}的划分方案数,即:B[0] = 1;
Bell(0) = 1,
Bell(n+1) = C(n,0)*Bell(0)+C(n,1)*Bell(1)+...+C(n,n)*Bell(n)
每一个Bell数都是第二类Stirling数的和,即:
Bell(n) = str2(n,1)+str2(n,2)+...+str2(n,n)
Bell(0) = 1,
Bell(n+1) = C(n,0)*Bell(0)+C(n,1)*Bell(1)+...+C(n,n)*Bell(n)
每一个Bell数都是第二类Stirling数的和,即:
Bell(n) = str2(n,1)+str2(n,2)+...+str2(n,n)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
const int maxn = 100;
int str2[maxn][maxn],be[maxn];
void stirling2(int n)
{
for(int i = 1; i <= n; i++)
{
str2[i][i] = 1 ;
for(int j = 1; j < i; j++)
{
str2[i][j]=str2[i-1][j-1]+j*str2[i-1][j];
}
}
}
void bell(int n)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
be[i]=be[i]+str2[i][j] ;
}
}
}
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
memset(str2,0,sizeof(str2));
stirling2(n);
memset(be,0,sizeof(be));
bell(n);
printf("%d\n",be[n]);
}
return 0;
}