Topic links : https://www.lydsy.com/JudgeOnline/problem.php?id=1079
AC Code:
1 / * 2 direct compression state is obviously not feasible, if we consider the color is not the same restriction is not adjacent to it, 3 if the number of pieces of wood can be stained two paints of the same, we can consider two paints no difference. 4 provided dp [a1] [a2] [ a3] [a4] [a5] can be transfected to block the paint has a number of programs ...... a1 species. 5 But there is a limit color of the adjacent, if the last number of colors used to paint k, 6 then this time there is a number of k-1 color paint can not be used, when the transfer note. . 7 * / . 8 # the include <the iostream> . 9 # the include <stdio.h> 10 # the include < String .h> . 11 # the include <algorithm> 12 is # the include <the bitset> 13 is # the include <the ctime> 14 # the include <climits> 15 the include # < SET > 16 # include <map> 17 # include <cctype> 18 # include <cmath> 19 # include <deque> 20 # include <queue> 21 # include <stack> 22 # include <vector> 23 # include <functional> 24 using namespace std; 25 26 typedef long long LL; 27 const int maxn=16; 28 const LL mod=1e9+7; 29 int n, x[16]; 30 LL f[16] [ 16 ] [ 16 ] [ 16 ] [ 16 ] [ . 6 ]; /// F arrays can represent currently a paint coating once more, before it can be painted twice a .... b is a coating k times can paint coating 31 is BOOL DP [ 16 ] [ 16 ] [ 16 ] [ 16 ] [ 16 ] [ . 6 ]; 32 33 is LL Dp ( int a, int B, int C, int D, int E, int K) 34 is { 35 LL T = 0 ; 36 IF(DP [A] [B] [C] [D] [E] [K]) 37 [ return F [A] [B] [C] [D] [E] [K]; 38 is IF (A + B + == E + D + C 0 ) 39 return . 1 ; 40 IF (A) 41 is T = T + (A- (K == 2 )) * Dp (A- . 1 , B, C, D, E, . 1 ); /// one kind of color can be dyed in one block, can be transfected into a block 0 (so that a-1), if the last number of paint colors using the 2, then this time there is a color number 1 the paint can not be used 42 is IF (B) 43 is T = T + (B- (K == . 3 )) * Dp (a + . 1 , B- . 1 , C, D, E, 2 ); ///One kind of dye color can be two blocks, which can be transfected into a block (so b-1, a + 1) , if the last number of 3 colors using the paint, this time there is a color number 2 paint can not be used 44 is IF (C) 45 T = T + (the C-(K == . 4 )) * Dp (a, B + . 1 , the C- . 1 , D, E, . 3 ); /// a way 3 cubes dye color can be dyed into a block 2 (so c-1, b + 1) , if the last number of colors used to paint 4, then this time there is a number of paint colors on 3 not used 46 is IF (D) 47 T = T + (D- (K == . 5 )) * Dp (a, B, C + . 1 , D- . 1 , E, . 4 ); /// one kind of dye may be 4 a block color, can be dyed into a 3 cubes (so d-1, c + 1) , if the last number of 5 using the paint color, then this time there is a color number can not be used to paint 4 48 IF (E) 49 + E = T * T Dp (A, B, C, D + . 1 , E- . 1 , . 5 ); /// one kind of color can be dyed five blocks, that can be transfected into four blocks (it e-1 , d + 1), if it can be dyed with a color of the box 5, because the subject conditions. 1 <= CI <=. 5, and thus the description he must not have been previously used 50 DP [a] [B] [C] [ D] [E] [K] =. 1; 51 is return F [A] [B] [C] [D] [E] [K] = (T% MOD); 52 is } 53 is 54 is int main () 55 { 56 is Scanf ( " % D " , & n-); 57 is for ( int I = . 1 ; I <= n-; I ++ ) 58 { 59 int y; 60 scanf("%d", &y); 61 x[y]++; 62 } 63 printf("%lld\n", Dp(x[1], x[2], x[3], x[4], x[5], 0)); 64 return 0; 65 }