[bzoj1079]着色方案

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <queue>
 7 #include <string>
 8 #include <vector>
 9 using namespace std;
10 
11 int n,x,tot[10];
12 long long dp[16][16][16][16][16][16];
13 long long f(int a,int b,int c,int d,int e,int l){
14     if(dp[a][b][c][d][e][l]!=-1)return dp[a][b][c][d][e][l];
15     #define t dp[a][b][c][d][e][l]
16     t=0;
17     if(a+b+c+d+e==0)return t=1;
18     if(a>0)t+=(a-(l==2))*f(a-1,b,c,d,e,1);
19     if(b>0)t+=(b-(l==3))*f(a+1,b-1,c,d,e,2);
20     if(c>0)t+=(c-(l==4))*f(a,b+1,c-1,d,e,3);
21     if(d>0)t+=(d-(l==5))*f(a,b,c+1,d-1,e,4);
22     if(e>0)t+=e*f(a,b,c,d+1,e-1,5);
23     return t%=1000000007;
24 }
25 int main(){
26     scanf("%d",&n);
27     for(int i=1;i<=n;i++)scanf("%d",&x),tot[x]++;
28     memset(dp,-1,sizeof(dp));
29     printf("%lld\n",f(tot[1],tot[2],tot[3],tot[4],tot[5],0));
30 }
View Code

 

posted @ 2017-02-01 10:13  KingSann  阅读(75)  评论(0编辑  收藏  举报