标签:预处理 文件 分享 图片 space ++ clear 正整数 for
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #define ll long long 5 #define N 60 6 #define M 1510 7 #define mo 1000000007 8 using namespace std; 9 int n; 10 ll a[N],sum[N],f[N][M],jc[M],c[M][M],ans; 11 int main() 12 { 13 freopen("photo.in","r",stdin),freopen("photo.out","w",stdout),scanf("%d",&n); 14 for (int i=1;i<=n;i++) scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i]; 15 jc[0]=c[0][0]=1; for (int i=1;i<=1500;i++) jc[i]=jc[i-1]*i%mo; 16 for (int i=1;i<=1500;i++) 17 { 18 c[i][0]=c[i][i]=1; 19 for (int j=1;j<=i-1;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mo; 20 } 21 f[1][sum[1]-1]=1; 22 for (int i=2;i<=n;i++) 23 for (int j=0;j<=sum[i-1];j++) 24 if (f[i-1][j]) 25 for (int k=1;k<=a[i];k++) 26 for (int p=0;p<=min(k,j);p++) 27 (f[i][j-p+a[i]-k]+=f[i-1][j]*c[j][p]%mo*c[a[i]-1][k-1]%mo*c[sum[i-1]+1-j][k-p]%mo)%=mo; 28 ans=f[n][0]; 29 for (int i=1;i<=n;i++) ans=ans*jc[a[i]]%mo; 30 printf("%lld",ans); 31 }
标签:预处理 文件 分享 图片 space ++ clear 正整数 for
原文地址:https://www.cnblogs.com/Comfortable/p/10339519.html