# bzoj1079[SCOI2008]着色方案

bzoj1079[SCOI2008]着色方案

 1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #define inc(i,j,k) for(int i=j;i<=k;i++)
5 #define ll long long
6 #define mod 1000000007
7 using namespace std;
8
9 ll f[16][16][16][16][16][6],k,c[16],rem[6];
10 ll dfs(int a,int b,int c,int d,int e,int g){
11     if(a+b+c+d+e==0)return 1; long long &ff=f[a][b][c][d][e][g];
12     if(ff!=-1)return ff; ff=0;
13     if(a)ff=(ff+(ll)(a-(g==1))*dfs(a-1,b,c,d,e,0))%mod;
14     if(b)ff=(ff+(ll)(b-(g==2))*dfs(a+1,b-1,c,d,e,1))%mod;
15     if(c)ff=(ff+(ll)(c-(g==3))*dfs(a,b+1,c-1,d,e,2))%mod;
16     if(d)ff=(ff+(ll)(d-(g==4))*dfs(a,b,c+1,d-1,e,3))%mod;
17     if(e)ff=(ff+(ll)(e-(g==5))*dfs(a,b,c,d+1,e-1,4))%mod;
18     return ff;
19 }
20 int main(){
21     scanf("%d",&k); inc(i,1,k)scanf("%d",&c[i]),rem[c[i]]++;
22     memset(f,-1,sizeof(f)); printf("%lld",dfs(rem[1],rem[2],rem[3],rem[4],rem[5],0));
23     return 0;
24 }

20160517

posted @ 2016-08-03 13:55  YuanZiming  阅读(...)  评论(... 编辑 收藏