Bzoj1079: [scoi2008] coloring scheme

Source: Internet
Author: User
1079: [scoi2008] coloring scheme time limit: 10 sec memory limit: 162 MB
Submit: 822 solved: 525
[Submit] [Status] Description

N blocks are arranged in one row, numbered from left to right as 1 ~ N. You have k colors of paint, where the I-color paint is enough to paint CI blocks. All paint is enough to fill all blocks, that is, C1 + C2 +... + ck = n. It is difficult to paint two adjacent blocks in the same color, so you want to calculate the color of any two adjacent blocks.

Input

The first row is a positive integer k, and the second row contains k integers C1, C2,..., CK.

Output

Output an integer, that is, the result of the total number of Modulo 1,000,000,007.

Sample input3
1 2 3
Sample output10
Hint

 

[Example 2] Input 5 2 2 2 2 2 output 39480 [Example 3] Input 10 1 1 1 2 2 3 3 4 5 5 output 85937576 data scale] 50% of data meet: 1 <= k <= 5, 1 <= CI <= 3 100% of data satisfied: 1 <= k <= 15, 1 <= CI <= 5

 

Source

Question:

I thought for a morning that I could not do anything...

The difficulty of this question is that, if the State is represented by 15 numbers ranging from 1 to 5, t is inevitable... Zookeeper did not expect the remaining several identical paints to be treated equally. It would only take one time...

If I have been violent, maybe I can think of it?

Code:

 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #define inf 1<<3012 #define maxn 500+10013 #define maxm 500+10014 #define eps 1e-1015 #define ll long long16 #define pa pair<int,int>17 #define mod 100000000718 using namespace std;19 inline int read()20 {21     int x=0,f=1;char ch=getchar();22     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}23     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}24     return x*f;25 }26 ll f[16][16][16][16][16][6];27 bool mark[16][16][16][16][16][6];28 int n,x,a[6];29 ll dp(int a,int b,int c,int d,int e,int k)30 {31    if(mark[a][b][c][d][e][k])return f[a][b][c][d][e][k];32    if(a+b+c+d+e==0)return 1;33    ll t=0;34    if(a)t+=(a-(k==2))*dp(a-1,b,c,d,e,1);35    if(b)t+=(b-(k==3))*dp(a+1,b-1,c,d,e,2);    36    if(c)t+=(c-(k==4))*dp(a,b+1,c-1,d,e,3);37    if(d)t+=(d-(k==5))*dp(a,b,c+1,d-1,e,4);38    if(e)t+=e*dp(a,b,c,d+1,e-1,5);39    mark[a][b][c][d][e][k]=1;40    return f[a][b][c][d][e][k]=(t%mod);41 }42 int main()43 {44     freopen("input.txt","r",stdin);45     freopen("output.txt","w",stdout);46     n=read();47     while(n--)x=read(),a[x]++;48     printf("%lld\n",dp(a[1],a[2],a[3],a[4],a[5],0));49     return 0;50 }
View code

 

Bzoj1079: [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.