查看原帖
338147
01bit楼主2024/11/20 14:56
#include<cstdio>
using namespace std;
typedef long long ll;
ll read(){
    char c=getchar();
    ll v=0,f=1;
    while(c<'0'||'9'<c){
        if(c=='-')f=-1;
        c=getchar();
    }
    while('0'<=c&&c<='9'){
        v=(v<<3)+(v<<1)+(c^48);
        c=getchar();
    }
    return v*f;
}
const ll mod=1e9+7;
const ll N=100+5,M=15+5;
ll n=0,m,c[N];
ll c1=0,c2=0,c3=0,c4=0,c5=0;
ll f[M][M][M][M][M];
void update(ll &x,ll y){
    y%=mod;
    x=(x+y)%mod;
}
int main(){
    m=read();
    for(ll i=1;i<=m;i++){
        c[i]=read();
        n+=c[i];
        if(c[i]==5)c5++;
        else if(c[i]==4)c4++;
        else if(c[i]==3)c3++;
        else if(c[i]==2)c2++;
        else c1++;
    }
    f[c5][c4][c3][c2][c1]=1;
    for(ll x5=c5;x5>=0;x5--)
        for(ll x4=c4+c5;x4>=0;x4--)
            for(ll x3=n-c1-c2;x3>=0;x3--)
                for(ll x2=n-c1;x2>=0;x2--)
                    for(ll x1=n;x1>=0;x1--){
                        ll t=f[x5][x4][x3][x2][x1];
                        if(!t)continue;
                        fprintf(stderr,"f(%lld,%lld,%lld,%lld,%lld)=%lld\n",x5,x4,x3,x2,x1,t);
                        if(x1)update(f[x5][x4][x3][x2][x1-1],t*x1);
                        if(x2)update(f[x5][x4][x3][x2-1][x1+1],t*x2);
                        if(x3)update(f[x5][x4][x3-1][x2+1][x1],t*x3);
                        if(x4)update(f[x5][x4-1][x3+1][x2][x1],t*x4);
                        if(x5)update(f[x5-1][x4+1][x3][x2][x1],t*x5);
                    }
    printf("%lld",f[0][0][0][0][0]);
    return 0;
}
2024/11/20 14:56
加载中...