# 解析：

### 思路：

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
re int num;
re char c;
while(!isdigit(c=gc()));num=c^48;
while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
return num;
}

int f[16][16][16][16][16][6];
cs int mod=1000000007;

inline int dp(int a,int b,int c,int d,int e,int l){
if((a|b|c|d|e)==0)return 1;
if(f[a][b][c][d][e][l])return f[a][b][c][d][e][l];
int &now=f[a][b][c][d][e][l];
if(a)now=(now+1ll*(a-(l==2))*dp(a-1,b,c,d,e,1))%mod;
if(b)now=(now+1ll*(b-(l==3))*dp(a+1,b-1,c,d,e,2))%mod;
if(c)now=(now+1ll*(c-(l==4))*dp(a,b+1,c-1,d,e,3))%mod;
if(d)now=(now+1ll*(d-(l==5))*dp(a,b,c+1,d-1,e,4))%mod;
if(e)now=(now+1ll*e*dp(a,b,c,d+1,e-1,5))%mod;
return now;
}

int cnt[6],k;
signed main(){
k=getint();
for(int re i=1;i<=k;++i){
++cnt[getint()];
}
cout<<dp(cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],0);
return 0;
}

posted on 2018-10-25 19:15  zxyoi_dreamer  阅读(...)  评论(... 编辑 收藏