# bzoj 1079 着色方案

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cmath>
5 #include<cstdlib>
6 #include<cstring>
7 #include<queue>
8 #include<map>
9 #include<vector>
10 #define ll long long
11 #define inf 2147483611
12 #define MAXN 17
13 #define MOD 1000000007
14 using namespace std;
16 {
17     ll x=0,f=1;char ch=getchar();
18     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
19     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
20     return x*f;
21 }
22 ll n,dp[MAXN][MAXN][MAXN][MAXN][MAXN][7],t[10];
23 ll dfs(int t1,int t2,int t3,int t4,int t5,int ban)
24 {
25     ll& res=dp[t1][t2][t3][t4][t5][ban];
26     if(dp[t1][t2][t3][t4][t5][ban]) return dp[t1][t2][t3][t4][t5][ban];
27     if(t1+t2+t3+t4+t5==0) return 1;
28     if(t1&&ban==2) (res+=(t1-1)*dfs(t1-1,t2,t3,t4,t5,1))%=MOD;
29     if(t1&&ban!=2) (res+=t1*dfs(t1-1,t2,t3,t4,t5,1))%=MOD;
30     if(t2&&ban==3) (res+=(t2-1)*dfs(t1+1,t2-1,t3,t4,t5,2))%=MOD;
31     if(t2&&ban!=3) (res+=t2*dfs(t1+1,t2-1,t3,t4,t5,2))%=MOD;
32     if(t3&&ban==4) (res+=(t3-1)*dfs(t1,t2+1,t3-1,t4,t5,3))%=MOD;
33     if(t3&&ban!=4) (res+=t3*dfs(t1,t2+1,t3-1,t4,t5,3))%=MOD;
34     if(t4&&ban==5) (res+=(t4-1)*dfs(t1,t2,t3+1,t4-1,t5,4))%=MOD;
35     if(t4&&ban!=5) (res+=t4*dfs(t1,t2,t3+1,t4-1,t5,4))%=MOD;
36     if(t5) (res+=t5*dfs(t1,t2,t3,t4+1,t5-1,5))%=MOD;
37     //cout<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<t5<<" "<<ban<<" "<<res<<" "<<dp[t1][t2][t3][t4][t5][ban]<<endl;
38     return res;
39 }
40 int main()
41 {
45 }