# BZOJ1079 SCOI2008 着色方案

3
1 2 3

10

## Hint

100%的数据满足：1 <= k <= 15, 1 <= ci <= 5

## Solution

$f(a,b,c,d,e,last)$表示剩余个数为$1，2，3，4，5$的油漆分别有$a,b,c,d,e$种，上一个木块用的颜料剩余$last$个时涂完所有颜料的方案数。

$f(a,b,c,d,e,last)=\begin{array}{cc}\\ \\ \\ \\ (a-[last==1])*f(a-1,b,c,d,e,0)\\+(b-[last==2])*f(a+1,b-1,c,d,e,1) \\+(c-[last==3])*f(a,b+1,c-1,d,e,2)\\+(d-[last==4])*f(a,b,c+1,d-1,e,3)\\+(e-[last==5])*f(a,b,c,d+1,e-1,4) \end{array}$

## Code

#include<cstdio>
#include<algorithm>
#define LL long long

const LL mod=1000000007;
int n,c,num[6];
LL f[16][16][16][16][16][16];

inline LL dfs(int a,int b,int c,int d,int e,int last){
if (a<0||b<0||c<0||d<0||e<0) return 0;
if (a+b+c+d+e==0) return 1;
LL &T=f[a][b][c][d][e][last];
if (T) return T;
//1
T=T+(a-(last==1))*dfs(a-1,b,c,d,e,0)%mod;
T%=mod;
//2
T=T+(b-(last==2))*dfs(a+1,b-1,c,d,e,1)%mod;
T%=mod;
//3
T=T+(c-(last==3))*dfs(a,b+1,c-1,d,e,2)%mod;
T%=mod;
//4
T=T+(d-(last==4))*dfs(a,b,c+1,d-1,e,3)%mod;
T%=mod;
//5
T=T+(e-(last==5))*dfs(a,b,c,d+1,e-1,4)%mod;
T%=mod;
return T;
}

int main(){
scanf("%d",&n);
for (int i=1;i<=n;++i)
scanf("%d",&c),++num[c];
printf("%lld",dfs(num[1],num[2],num[3],num[4],num[5],0));
}

posted @ 2017-11-07 19:00  Hyheng  阅读(70)  评论(0编辑  收藏