http://codeforces.com/contest/568/problem/B
题意:题意还挺绕的,其实就是说:要你求出一个图,要求保证其中有至少一个点不连任何边,然后其他连边的点构成的每个联通块都必须构成完全连通图
思路:f[i][j]代表i个点,构成j个联通块的方案数
f[i][j]=f[i][j-1]*j(代表与其中一个联通块合并)+f[i-1][j-1](代表新开一个联通块)
然后答案是Σc[n][i]*f[i][j]
1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 #define ll long long 7 const ll Mod=1000000007; 8 ll f[4005][4005],c[4005][4005]; 9 int n; 10 ll Pow(ll x,ll y){ 11 ll res=1; 12 while (y){ 13 if (y&1) res=(res*x)%Mod; 14 y/=2; 15 x=(x*x)%Mod; 16 } 17 return res; 18 } 19 int read(){ 20 int t=0,f=1;char ch=getchar(); 21 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 22 while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} 23 return t*f; 24 } 25 int main(){ 26 n=read(); 27 ll ans=0; 28 for (int i=1;i<=n;i++) c[i][0]=c[i][i]=1; 29 for (int i=2;i<=n;i++) 30 for (int j=1;j<i;j++) 31 c[i][j]=(c[i-1][j]+c[i-1][j-1])%Mod; 32 f[0][0]=1; 33 for (int i=1;i<=n;i++) 34 for (int j=1;j<=i;j++) 35 f[i][j]=((1LL*f[i-1][j]*j)%Mod+f[i-1][j-1])%Mod; 36 for (int i=0;i<n;i++) 37 for (int j=0;j<=i;j++) 38 ans=(ans+f[i][j]*c[n][i])%Mod; 39 printf("%lld ",ans); 40 return 0; 41 }