比赛 2022级DP专题练习赛8 评测结果 AAAAAAAAAA
题目名称 着色方案 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-03-01 20:54:35
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=75+5;
const ll mod=1000000007;
int n,m;
int c[N];
ll fac[N],inv[]={1,1,500000004,166666668,41666667,808333339};
ll f[N];
ll C(int x,int y){
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
	freopen ("color.in","r",stdin);
	freopen ("color.out","w",stdout);
	scanf("%d",&m);
	for (int i=1;i<=m;i++){
	    scanf("%d",&c[i]);n+=c[i];
    }f[0]=fac[0]=1;
    for (int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
    for (int i=1;i<=m;i++){
        for (int j=n;j>=0;j--){
            (f[j]*=inv[c[i]])%=mod;
            for (int k=1;k<=c[i]-1;k++){
                if (j-k<0)break;
                (f[j]+=f[j-k]*C(c[i]-1,k)%mod*inv[c[i]-k]%mod)%=mod;
            }
        }
    }
    ll ans=0;
    for (int i=0;i<=n;i++){
        (ans+=fac[n-i]*((i&1)?mod-f[i]:f[i])%mod)%=mod;
    }
    printf("%lld\n",ans);
}