# BZOJ 1079: [SCOI2008]着色方案 DP

3
1 2 3

10

## HINT

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

## Source

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
const int N=550;
const int MOD = 1e9 + 7;

int k,dp[16][16][16][16][16][6];//1//2//3//4//5//ji
int dfs(int a,int b,int c,int d,int e,int f) {
int& ret = dp[a][b][c][d][e][f];
if(ret) return ret;
if(a)  ret += (1ll*(a - (f == 2)) * dfs(a-1,b,c,d,e,1)) % MOD,ret %=MOD;
if(b)  ret += (1ll*(b - (f == 3)) * dfs(a+1,b-1,c,d,e,2)) % MOD,ret %=MOD;
if(c)  ret += (1ll*(c - (f == 4)) * dfs(a,b+1,c-1,d,e,3) )% MOD,ret %=MOD;
if(d)  ret += (1ll*(d - (f == 5)) * dfs(a,b,c+1,d-1,e,4) )% MOD,ret %=MOD;
if(e)  ret += (1ll* e * dfs(a,b,c,d+1,e-1,5)) %MOD,ret %=MOD;
return ret%MOD;
}
int h[N],c[N];
int main() {
scanf("%d",&k);
for(int i = 0; i < 6; i++) dp[0][0][0][0][0][i] = 1;
for(int i = 1; i <= k; i++) {
scanf("%d",&c[i]);
h[c[i]]++;
}
printf("%d\n",dfs(h[1],h[2],h[3],h[4],h[5],0));
return 0;
}

posted @ 2016-01-07 15:22  zxhl  阅读(...)  评论(... 编辑 收藏