Transmission Door
Thinking of solving problems
A cancer problem, and just started to write a strange hash, the result T 5 points. Later deep (kan) into (le) think (TI) examination (Jie), found that the range of C is very small, set $f[a][b][c][d][e][pre]?$ said to be able to paint a lattice has a, two lattice of B ... The pre represents the color of the previous painting, the transfer look at the code, better think.
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Const intMAXN = -;Const intMoD = 1e9+7; typedefLong LongLL;intK,C[MAXN],CNT[MAXN];intf[maxn][maxn][maxn][maxn][maxn][7];intDfsintAintBintCintDintEintpre) { if(F[a][b][c][d][e][pre])returnF[a][b][c][d][e][pre]; if(!a &&!b &&!c &&!d &&!e)returnf[a][b][c][d][e][pre]=1; intret=0; if(a) ret= (ret+ (LL) (A-(pre==2)) *dfs (A-1, B,c,d,e,1)%mod)%MoD; if(b) ret= (ret+ (LL) (b (pre==3)) *dfs (A +1, B-1, C,d,e,2)%mod)%MoD; if(c) ret= (ret+ (LL) (C (pre==4)) *dfs (a,b+1, C-1, D,e,3)%mod)%MoD; if(d) ret= (ret+ (LL) (D (pre==5)) *dfs (a,b,c+1, d1E4)%mod)%MoD; if(e) ret= (ret+ (LL) E*dfs (a,b,c,d+1, E-1,5)%mod)%MoD; returnf[a][b][c][d][e][pre]=ret;}intMain () {scanf ("%d",&k); for(intI=1; i<=k;i++) scanf ("%d", &c[i]), cnt[c[i]]++; printf ("%d", DFS (cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],0)); return 0;}
View Code
Luogu P2476 [SCOI2008] coloring scheme