#include <iostream>
using namespace std;
const long long MOD=1000000007;
const int N=2000;
int n,m;
long long a[20005],sum,c[2005][2005] ;
// Sum_{k>=1} (k-1)^n/2^k
//a(n) = Sum_{k=1..n} binomial(n, k)*a(n-k), a(0) = 1.
int main() {
for (int i=0; i<=N; i++)
c[i][0]=c[i][i]=1,c[i][1]=i%MOD;
for (int i=3; i<=N; i++)
for (int j=2; j<i; j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
cin>>n;
a[0]=1;
for (int i=1; i<=n; i++){
sum=0;
for (int j=1; j<=i; j++)
sum=(sum+(c[i][j]*a[i-j])%MOD)%MOD;
a[i]=sum;
}
cout<<a[n]%MOD;
return 0;
}
串联计数c++代码
最新推荐文章于 2024-11-10 14:57:19 发布