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
The design state of the problem is very ingenious. Set F[a][b][c][d][e][l] said enough to paint 1 times a kind of paint, enough to paint 2 times a B paint, enough to paint 3 times the C type of paint, enough to paint 4 times there is a D paint, enough to paint 5 times e paint, the last used is enough to paint l times. The state transfer is simple.
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespacestd;Const intBuffersize=1<< -;Charbuffer[buffersize],*head,*Tail;inlineCharGetchar () {if(head==tail) { intL=fread (Buffer,1, Buffersize,stdin); Tail= (Head=buffer) +l; } return*head++;} InlineintRead () {intx=0, f=1;CharC=GetChar (); for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1; for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedefLong Longll;Const intMod=1000000007;intf[ -][ -][ -][ -][ -][6];intdpintAintBintCintDintEintl) {if(a+b+c+d+e==0)return 1; int& ans=F[a][b][c][d][e][l]; if(ans>=0)returnans;ans=0; if(a) (ans+= (LL) (A-(l==2)) *DP (A-1, B,c,d,e,1)%mod)%=MoD; if(b) (ans+= (LL) (B (l==3)) *DP (A +1, B-1, C,d,e,2)%mod)%=MoD; if(c) (ans+= (LL) (C (l==4)) *DP (a,b+1, C-1, D,e,3)%mod)%=MoD; if(d) (ans+= (LL) (D (l==5)) *DP (a,b,c+1, d1E4)%mod)%=MoD; if(e) (ans+= (LL) E*DP (a,b,c,d+1, E-1,5)%mod)%=MoD; returnans;}intn,t[6];intMain () {memset (F,-1,sizeof(f)); intN=read (); Rep (I,1, n) t[read ()]++; printf ("%d\n", DP (t[1],t[2],t[3],t[4],t[5],0)); return 0;}
View Code
BZOJ1079: [SCOI2008] Coloring scheme