"Bzoj 1079" [SCOI2008] coloring scheme

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.