Description
There are n pieces of wood lined up, numbered from left to right in 1~n. You have a k color of paint, wherein the first color of the paint is enough to tu ci a wood block. All the paint is just enough to fill all the pieces of wood, namely c1+c2+...+ck=n. Adjacent two pieces of wood painted the same color looks very ugly, so you want to count any two adjacent wood color different coloring scheme.
Input
The first behavior is a positive integer k, the second line contains k integers c1, c2, ..., CK.
Output
Outputs an integer, which is the result of modulo 1,000,000,007 for the total number of scenarios.
Sample Input3
1 2 3Sample OutputTenHINT
100% of data meet: 1 <= k <=, 1 <= ci <= 5
Established status F[i][j][k][l][m][n] that now left 5,4,3,2,1 card of the type has i,j,k,l,m, the last election for which one (after all, which is the same) transfer obviously ...
1#include <cstdio>2 #definell Long Long3#include <cstring>4 using namespacestd;5 Const intMod=1000000007;6ll f[ -][ -][ -][ -][ -][6];7 intx[6],n;8LL DP (intAintBintCintDintEintl) {9ll t=0;Ten if(f[a][b][c][d][e][l]!=-1)returnF[a][b][c][d][e][l]; One if(a+b+c+d+e==0)return 1; A if(a) t+= (A-(l==2)) *DP (A-1, B,c,d,e,1); - if(b) t+=-B (l==3)) *DP (A +1, B-1, C,d,e,2); - if(c) t+= (-C (l==4)) *DP (a,b+1, C-1, D,e,3); the if(d) t+= (-D (l==5)) *DP (a,b,c+1, d1E4); - if(e) T+=E*DP (a,b,c,d+1, E-1,5); - returnF[a][b][c][d][e][l]= (t%MoD); - } + - intMain () { +memset (f,-1,sizeof(f)); Ascanf"%d",&n); at for(intI=1; i<=n;i++) { - intT; -scanf"%d",&t); -x[t]++; - } -printf"%lld", DP (x[1],x[2],x[3],x[4],x[5],0)); in}
"Bzoj 1079" [SCOI2008] coloring scheme